Adding system date & time to a photo

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
BigBlueMan
Posts: 2
Joined: 2011-08-10T17:09:53-07:00
Authentication code: 8675308

Adding system date & time to a photo

Post by BigBlueMan »

I'm using a batch file to download and generate weather graphic photos. Adding storm fronts, etc to a base map on an every ten minute basis.

I want to include the system date & time that the photos are made to each picture. I have a command that will do this if there is embedded EXIF data within the picture, but since I'm generating these outside the digital camera world, that information isn't available.

Any ideas as to how the system info can be pulled in?

This is the original command line:

convert master_24.jpg -font "Digital-7-italic" -pointsize 15 -fill white -annotate +60+400 %[exif:DateTimeOriginal] 24time.jpg
I'm using a fresh install of ImageMagick under Windows 7.

Any help would be appreciated.
ed
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adding system date & time to a photo

Post by fmw42 »

Not sure I understand, but in the unix world:


timedate=`date | tr " " "_"`
echo $timedate

Wed_Aug_10_18:07:02_PDT_2011


convert image <someprocessing> output_${timedate}.jpg

You can use pipe and sed to filter the timedate further to reformat as needed


I don't know how one would do the same in Windows, but see http://www.imagemagick.org/Usage/windows/
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Adding system date & time to a photo

Post by whugemann »

The system time is stored in the environment variable %TIME%. So a batch file taking the filename as a parameter would be:

Code: Select all

convert %1 -pointsize 15 -fill white -annotate +60+400 %TIME% %~dpn1_time%~x1
In a more flexible approach, you can store the result of any DOS command in a variable, so:

Code: Select all

SETLOCAL EnableDelayedExpansion
FOR /F %%i in ('time /t') DO SET TT=%%i
convert %1 -pointsize 70 -fill white -annotate +60+400 !TT! %~dpn1_time%~x1
See http://www.imagemagick.org/Usage/windows/#single for an example how the output can be re-formatted in this approach. Over there, this is demonstrated for the EXIF time stamp, but it would work very similar for any other string provided at stdout.
Wolfgang Hugemann
BigBlueMan
Posts: 2
Joined: 2011-08-10T17:09:53-07:00
Authentication code: 8675308

Re: Adding system date & time to a photo

Post by BigBlueMan »

Thanks! The last suggestion using the %TIME% command appears to have done the trick. Going to play with it a bit and see what I can make it do.
Post Reply