Static image creation

108 views
Skip to first unread message

Ernest Jillson

unread,
Jun 27, 2021, 6:23:14 PM6/27/21
to weewx...@googlegroups.com
Anyone know of any skins that can produce a static image with most parameters in either text or dial format? The web pages are great, but I'd love to find something that creates an image with T, MaxT, MinT, Wind, Precip (at the least) and ftp it to a friend's web site.
 
Thanks in advance,
 
Ernie

vince

unread,
Jun 27, 2021, 7:38:14 PM6/27/21
to weewx-user
I don't know of any skins, but I did find one page with examples of how to overlay text using the 'convert' program that comes with ImageMagick.

https://www.meteobridge.com/wiki/index.php/Weather_Cam_Image_Handling has a bunch of examples and what the resulting images look like.

vince

unread,
Jun 27, 2021, 10:08:01 PM6/27/21
to weewx-user
I did some more research and figured out one way to do it.
  • created a skin with a minimal 'current.html.tmpl' file with the string I want overlaid on the image
  • I already have a webcam taking a snapshot every few minutes ('motion' running on a raspi with a usb cam)
  • created a quick script to overlay the data on the image

Script contents:

MSG=`cat /mnt/ramdisk/current.html`
convert /mnt/ramdisk/motion/image.jpg -alpha on                                    \
  \( +clone -scale x5% -threshold 101% -channel A -fx "0.5" \) \
  -gravity north -composite                                     \
  -fill white -pointsize 18 -annotate 0,0 "${MSG}" /mnt/ramdisk/motion/image-overlaid.jpg

Template file 'current.html.tmpl' contents:

current=$current.outTemp.raw F, max=$day.outTemp.max.raw F, min=$day.outTemp.min.raw F

Example output:

image-overlaid.jpg


Andrew Elwell

unread,
Jun 27, 2021, 10:53:55 PM6/27/21
to weewx...@googlegroups.com
On Mon, 28 Jun 2021 at 08:23, Ernest Jillson <etji...@gmail.com> wrote:
>
> Anyone know of any skins that can produce a static image with most parameters in either text or dial format? The web pages are great, but I'd love to find something that creates an image with T, MaxT, MinT, Wind, Precip (at the least) and ftp it to a friend's web site.
>
> Thanks in advance,

IThe box my webcam (actually a pi + pi camera) is on a different box
to my weewx host, I found the easiest way was to save the weather
conditions I was interested in via mqttwarn[1] which dumps it down to
a local file (since 'loop' outputs may not align with the timings when
I need to grab an image.

The image is grabbed every 5 mins:
pi@stupify:~ $ crontab -l | grep cam
*/5 5-20 * * * /home/pi/llamacam.py

pi@stupify:~ $ cat /home/pi/llamacam.py
#!/usr/bin/python3
import io
import picamera
from PIL import Image
from PIL import ImageFont,ImageDraw
import time
import os

temperaturefile = '/var/www/html/weewx/test.txt'
image_out = '/var/www/html/webcam/latest.jpg'

text_overlay = '{}'.format(time.strftime('%a %Y-%m-%d %H:%M %Z'))
#print(os.path.getmtime(temperaturefile),time.time(),(time.time() -
os.path.getmtime(temperaturefile)))
if (time.time() - os.path.getmtime(temperaturefile)<= 300):
with open(temperaturefile, "r") as f:
temperature = float(f.read())
text_overlay += ', Outside Temp: {:.1f}°C'.format(temperature)
else:
text_overlay += ' (No temperature reading available)'


# Create the in-memory stream
stream = io.BytesIO()
with picamera.PiCamera() as camera:
camera.led = False
camera.resolution = (1920,1080)
camera.start_preview()
time.sleep(2)
camera.capture(stream, format='jpeg')
# "Rewind" the stream to the beginning so we can read its content
stream.seek(0)
image = Image.open(stream)

# add logo to bottom rightt
overlay = Image.open("lw_logo.png");
image.paste(overlay, (1400,750 ), overlay)

# add text too
font = ImageFont.truetype("Miriam.ttf", 36)
draw = ImageDraw.Draw(image)
draw.text((50, 1020), text_overlay, font=font, fill='rgb(0, 168, 162)')

image.save(image_out)




And that dumps out the following image


[1] https://github.com/jpmens/mqttwarn
llamacam.jpg

Ernest Jillson

unread,
Jun 28, 2021, 8:08:54 PM6/28/21
to weewx...@googlegroups.com
Thanks, everyone.
 
I will definitely need to grab some text from the feed or database, so either a simple skin or mqttwarn will work well for that. I have some experience with adding text to images using imagemagick. What I really would like is some dials. And I just came across a site with steel gauges that might be able to create the images I would like to add to the image background. Work keeps me busy, but I'm going to try to work on that a little at a time over the next few days.
 
Ernie

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/CAANX9yecbCTDTG3C5rezSqpftPcKZ%2BAZOcLOh43XqDw8caEufg%40mail.gmail.com.

Ernest Jillson

unread,
Jun 28, 2021, 9:30:12 PM6/28/21
to weewx...@googlegroups.com
Well, it turns out steel gauges doesn't save the gauges as images.  Oh well.
Reply all
Reply to author
Forward
0 new messages