|
Post by topher2880 on Sept 2, 2019 19:18:03 GMT -8
Not a huge issue, however has anyone else not got weather data on their snapshot images?
I have scoured the code and cant see why I dont seem to have it. Using v045 software. No errors come up, it just doesnt seem to print
I checked the font etc, even copied into main folder and called it by SkyCamera.py and still nothing. So, thought I would ask the question.
|
|
impactoz
Full Member
Posts: 142
Raspberry Pi: Yes
|
Post by impactoz on Sept 2, 2019 20:52:47 GMT -8
Yes I have seen it before - when I have tried playing around to make my own message. I think it came down to a malformed variable and the string could not be created properly...
Id suggest after you have built the msg string that you want to display to put in a print statement of it to determine if the msg is actually being formed first...
The txt message is actually placed on a button, a button that is black - so all the pieces need to work in the correct order...
Here is a custom msg string that works - but of course its my highly customised code - so read through it and look closely at just the img manipulation;
This is my simple picture of sunset - where it would show the words Sunset at [name of my box from my conflocal file] and the date... It does resizing and cropping for twitter...
print "Taking Sunset picture at ", dt.date.today(), dt.datetime.now().time() print "Sunset is calculated at: ", result['sunset'].time() camera.capture('static/sunset.jpg') basewidth = 440 # New Width of the image img = Image.open('static/sunset.jpg') # Now Resize and Crop it # draw.text((0, 0),myText,(255,0,127),font=font) wpercent = (basewidth / float(img.size[0])) hsize = int((float(img.size[1]) * float(wpercent))) img = img.resize((basewidth, hsize),1) area = (0, 0, 440, 220) img = img.crop(area) # Going to add a header of title (from config) and date.... draw = ImageDraw.Draw(img) font = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeSans.ttf", 16) myText = "Sunset at " + config.HEADERPIC + ": %s" % (dt.datetime.now().strftime('%d-%b-%Y')) color = 'rgb(255,255,255)' text_size = font.getsize(myText) button_size = (text_size[0]+20, text_size[1]+10) button_img = Image.new('RGBA', button_size, "black") button_draw = ImageDraw.Draw(button_img) button_draw.text((10, 5), myText, fill = color, font=font) img.paste(button_img, (0, 0))
# We have a new image, scaled and cropped for common twitter usage - lets save it for use later tonight img.save('static/sunset.jpg')
Or my code for the main picture that goes out every 5 mins to weatherstem
pil_im = Image.open('static/skycamera.jpg') draw = ImageDraw.Draw(pil_im) # Choose a font font = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeSans.ttf", 25)
# set up units #wind val = util.returnWindSpeed(state.ScurrentWindSpeed) WindStval = "{0:0.1f}".format(val) + util.returnWindSpeedUnit() val = util.returnWindSpeed(state.ScurrentWindGust) WindGtval = "{0:0.1f}".format(val) + util.returnWindSpeedUnit() val = util.returnTemperatureCF(state.currentOutsideTemperature) OTtval = "{0:0.1f}".format(val) + util.returnTemperatureCFUnit() val = state.currentTotalRain RDval = "{0:0.1f}".format(val) + "mm" val = state.currentSunlightUVIndex if val < 3: UVval = "Low" elif val >=3 and val < 6: UVval = "Moderate" elif val >=6 and val < 8: UVval = "High" elif val >=8 and val < 11: UVval = "Very High" else: UVval = "Extreme"
myText = config.HEADERPIC + ": %s Wind Speed: %s Wind Gust: %s Temp: %s Rain Today: %s UV: %s" % (dt.datetime.now().strftime('%d-%b-%Y %H:%M'),WindStval, WindGtval, OTtval, RDval, UVval)
# Draw the text color = 'rgb(255,255,255)' #draw.text((0, 0), myText,fill = color, font=font)
# get text size text_size = font.getsize(myText)
# set button size + 10px margins button_size = (text_size[0]+20, text_size[1]+10)
# create image with correct size and black background button_img = Image.new('RGBA', button_size, "black") # put text on button with 10px margins button_draw = ImageDraw.Draw(button_img) button_draw.text((10, 5), myText, fill = color, font=font)
# put button on source image in position (0, 0)
pil_im.paste(button_img, (0, 0)) bg_w, bg_h = pil_im.size # WeatherSTEM logo in lower left #size = 64 #WSLimg = Image.open("static/WeatherSTEMLogoSkyBackground.png") #WSLimg.thumbnail((size,size),Image.ANTIALIAS) #pil_im.paste(WSLimg, (0, bg_h-size))
# SkyWeather log in lower right #SWLimg = Image.open("static/SkyWeatherLogoSymbol.png") #SWLimg.thumbnail((size,size),Image.ANTIALIAS) #pil_im.paste(SWLimg, (bg_w-size, bg_h-size))
# Save the image pil_im.save('static/skycamera.jpg', format= 'JPEG')
The above having lots of extra code to manipulate the msg string.
I think if you examine the contents of msg... with some print statements around you will find that the code errors, traps, does not report a problem in the logfile, and therefore does not manipulate the image properly... The code for sending the picture WeatherStem is in a different declaration, so it sends a picture - the one that exists without the header...
|
|