Generating image with today's date
May 28, 2014 6:49 PM   Subscribe

Looking for a way to automate a process on a PC or Mac. I need a simple PNG, transparent background, with a text string of today's date in the lower third of the image. Each day at a certain time, this file would be generated and overwrite the previous file of the same name "Date.PNG".
posted by shinynewnick to Computers & Internet (7 answers total) 2 users marked this as a favorite
Imagemagick is probably the easiest way.

This works on linux for me, probably similar on mac. No idea on PC. blank.png should be a blank, transparent png.

convert blank.png -gravity south -annotate 0 "$(date)" DATE.png

Run that in a cron job once a day.
posted by smcameron at 7:18 PM on May 28, 2014

ImageMagick is the standard library for this sort of thing.
posted by empath at 7:20 PM on May 28, 2014

Imagemagick can create a new blank image for you, so you don't even need the blank.png. On my Mac, with imagemagick installed with HomeBrew, the following makes a 640x480 transparent png with the date in MM-DD-YYYY format in Arial at 16 pixels high.

convert -size 640x480 canvas:transparent -gravity south -font /Library/Fonts/Arial.ttf -pointsize 16 -annotate 0 "$(date +'%m-%d-%Y')" DATE.png
posted by zsazsa at 7:57 PM on May 28, 2014 [3 favorites]

Perfect answers so far, thank you!

For my purpose, I'd like to put it in the format of "May 28, 2014". What variable commands would I use for that format?
posted by shinynewnick at 8:01 PM on May 28, 2014

$(date +'%B %e, %Y')
posted by mce at 8:14 PM on May 28, 2014

If you are looking for other date formatting options (at least on a unix-y system) you can find all of the options in the man page for strftime. There are rather a multitude to choose from.
posted by mce at 9:49 AM on May 29, 2014

Worked just as I needed. Ended up installing MacPorts to help with adding ImageMagick to my Mac system. Found some more details to help with formatting, and with some trial and error ended up with this code:

convert -size 640x480 canvas:transparent -gravity south -font /Library/Fonts/MyriadPro-Bold.otf -pointsize 64 -channel RGBA -fill snow -stroke black -draw "text 1,80 '$(date +'%B %e, %Y')'" /Users/nick/Dropbox/Tricaster/Date.PNG

I've now set this up as a cron job, waiting to see if it all works in the background. Thanks everyone!
posted by shinynewnick at 9:21 AM on May 30, 2014 [1 favorite]

« Older I do a good bit of genealogy r...   |  I'm trying to exercise more, m... Newer »

You are not logged in, either login or create an account to post comments