Adding time stamp for single file in Windows

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
steahl
Posts: 3
Joined: 2014-01-06T13:44:29-07:00
Authentication code: 6789

Adding time stamp for single file in Windows

Post by steahl »

Hi,

I have an IP camera creating a jpg-file which is uploaded to my webserver. I want to add a time stamp to the file called image.jpg with the file date and time and save it with another name. The jpg contains no Exif-tags. I want to run the code in a Windows batch file. Can someone help me with this?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Adding time stamp for single file in Windows

Post by snibgo »

Do you want to modify the image to include the date/time or just change the name? The Windows "for" command can get the date/time of the file. See "help for" and "help rename".
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adding time stamp for single file in Windows

Post by fmw42 »

Alternately, you can put the date/time, etc in the comments field of the verbose information in the meta data of the file. see http://www.imagemagick.org/script/comma ... hp#comment
steahl
Posts: 3
Joined: 2014-01-06T13:44:29-07:00
Authentication code: 6789

Re: Adding time stamp for single file in Windows

Post by steahl »

Sorry I was unclear in my question. I want to time stamp the no-exif jpg in the same way the code below does for a jpg with exif-information.

convert PICT0001.JPG -font Arial -pointsize 20 -fill yellow -annotate +450+440 "%%[exif:DateTime]" PICT0001_trans.jpg

And I want to do that in a windows batch file, i.e. the double % signs. My line of thought is that I must declare a variable and then assign the "file modified date" to it somehow. And then use this variable as an argument for the annotate option. But my programming skills is not up for the job :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adding time stamp for single file in Windows

Post by fmw42 »

If the file already has the DateTime stamp in the EXIF meta data, then your command should work. If you are trying to add the Date/Time to the exif meta data, ImageMagick does not do that.

If you can look up the Data/Time on the system and put it into a variable, then you can use your command with the variable as follows.

date_time=$(date)
convert PICT0001.JPG -font Arial -pointsize 20 -fill yellow -annotate +450+440 "$date_time" PICT0001_trans.jpg

The above would be unix syntax. One of the Windows users would have to explain the syntax and how to get the data/time from the Windows OS
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Adding time stamp for single file in Windows

Post by snibgo »

@steahl: Did you type "help for" as I suggested?

Code: Select all

for %%A in (*.png) do (
  set FNAME=%%A
  set FDATE=%%~tA
  convert ...
)
snibgo's IM pages: im.snibgo.com
steahl
Posts: 3
Joined: 2014-01-06T13:44:29-07:00
Authentication code: 6789

Re: Adding time stamp for single file in Windows

Post by steahl »

Thanks for your help. I managed to get what I wanted with this code:

Code: Select all

for %%A in (image.jpg) do set FDATE=%%~tA
convert image.jpg -pointsize 20 -fill yellow -gravity southeast ^ -annotate +10+10 "%FDATE%" image_trans.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adding time stamp for single file in Windows

Post by fmw42 »

steahl wrote:

Code: Select all

for %%A in (image.jpg) do set FDATE=%%~tA
convert image.jpg -pointsize 20 -fill yellow -gravity southeast ^ -annotate +10+10 "%FDATE%" image_trans.jpg

Everything after ^ should be on a separate line. The ^ is the new line indicator and there should be nothing following it, not even a space. So it should properly be

Code: Select all

for %%A in (image.jpg) do set FDATE=%%~tA
convert image.jpg -pointsize 20 -fill yellow -gravity southeast ^
-annotate +10+10 "%FDATE%" image_trans.jpg

If you want it all on one line, then remove the ^

Code: Select all

for %%A in (image.jpg) do set FDATE=%%~tA
convert image.jpg -pointsize 20 -fill yellow -gravity southeast -annotate +10+10 "%FDATE%" image_trans.jpg
Post Reply