Add system date & time to image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
yds
Posts: 9
Joined: 2013-09-11T16:56:12-07:00
Authentication code: 6789

Add system date & time to image

Post by yds »

I want to be able to add the system time and date (not EXIF tag data) to an image running from command line. For the life of me, I cannot figure out how to get the system date. I am using IM on linux. (I have found on windows I can use %TIME% to return the system date and time, but doesn't work on linux). Here's an example, and I'm not sure what to put in place of SYSTEM_TIME_HERE to get the system date/time to annotate. Any help appreciated.

Code: Select all

convert source.jpg -pointsize 24 -fill white -undercolor '#00000080' -gravity SouthEast -annotate +0+5 SYSTEM_TIME_HERE output.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Add system date & time to image

Post by fmw42 »

datetime=`date`
echo $datetime
Mon Oct 7 19:55:11 PDT 2013

so get date info and put into a variable and then use the variable in the IM command -annotate, but put it in double quotes.


datetime=`date`
convert source.jpg -pointsize 24 -fill white -undercolor '#00000080' -gravity SouthEast -annotate +0+5 "$datetime" output.jpg
yds
Posts: 9
Joined: 2013-09-11T16:56:12-07:00
Authentication code: 6789

Re: Add system date & time to image

Post by yds »

Perfect! Thanks. Wasn't sure how to do both from one commandline, but tried it and worked beautifully!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Add system date & time to image

Post by fmw42 »

this also works in one command line:

convert source.jpg -pointsize 24 -fill white -undercolor '#00000080' -gravity SouthEast -annotate +0+5 "$(date)" output.jpg
Post Reply