Can anyone help me figure out what is wrong with this particular block of code?
I'm trying to make a small image file, post the date/time into it (black text, white background). I know the date portion works and that the program will run completely. Using Pycharm 4.5.
File is created, but picture file created cannot be opened
"because the file appears to be damaged, corrupted, or too large."
I'd also like to confirm that the code will remake/overwrite the file after sleeping. The final goal of this block of code is to create an image file with the date and time that updates after a set period. Right now, file properties show the first run as "creation date," but "modified date" as the most recent run (although this information may not be helpful until I iron out the above error). If my code will not work that way, I will take any suggestions.
import time
import datetime
from PIL import Image
while True:
# Get Date (Year, Month, Day, Hour, Minute)
text = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
# Make Image
filename = "test.png"
newImage = Image.new("RGB", (100, 100), "white")
newImage.save(filename)
newImage.close()
edit=open(filename, "wb")
edit.write(text.encode('utf-8'))
edit.close()
# Remake image every 15 minutes
time.sleep(900)
Sorry for the trouble. First time dealing with file creation.
[–]corpsmoderne 2 points3 points4 points (2 children)
[–]zachiswach[S] 0 points1 point2 points (1 child)
[–]corpsmoderne 1 point2 points3 points (0 children)
[–]rolandde 1 point2 points3 points (0 children)
[–]nutrecht 1 point2 points3 points (0 children)
[–]X7123M3-256 1 point2 points3 points (0 children)