More than a year ago, I wrote the tutorial how to add date time stamp to JPEG photos like old P&S film camera could do. It has been one of the most popular articles on this blog.

Many people requested different formats for the date time stamp. In the original script, the format is set by the ImagaMagick software and it is not directly changeable. However with a few simple modifications to the script, customization of the format can be achieved.

The code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
@ECHO OFF
SETLOCAL
SET _bytes=0
SET _count=0
SET _cmd=%1
SET _choice=0
IF NOT DEFINED _cmd SET _cmd=blank
IF %_cmd%==? GOTO :help
IF %_cmd%==/? GOTO :help
FOR /R %%G IN (*.jpg) DO CALL :process "%%G"
GOTO :total

:process
IF %_choice%==3 EXIT /B
SET _inname=%1
set _str=%_inname:_DT.=%
if NOT %_str%==%1 EXIT /B

SET _outname=%_inname:~0,-4%_DT.jpg

IF /I NOT "%_cmd%"=="ADDDT" GOTO :report %1
IF NOT %_choice%==4 CALL :ask %1
IF %_choice%==2 EXIT /B
IF %_choice%==3 ECHO Cancelling, please wait ... && EXIT /B
CALL :sum %1

identify -format %%w %_inname% >dttmpfile
set /p width=
DEL dttmpfile
ECHO Processing %_inname% ...

FOR /F "tokens=1,2,3,4,5,6 delims=: " %%a IN ('identify -format "%%[EXIF:DateTimeOriginal]" %_inname%') DO SET year=%%a&set month=%%b&set day=%%c&set hour=%%d&set min=%%e&set sec=%%f
set DTString="%month%/%day%/%year% %hour%:%min%:%sec%"
convert %_inname% -gravity NorthWest -font "Digital-7-Italic" -pointsize %pointsize% -fill white -annotate +%pointsize%+%pointsize% %DTString% %_outname%
EXIT /B

:ask
CHOICE /C YNCA /M "Process %~1 (Yes, No, Cancel, All)?"
SET _choice=%ERRORLEVEL%
EXIT /B

:report
CALL :sum  %1
ECHO Found %1
EXIT /B

:sum
SET /A _bytes+=%~z1/1000
SET /A _count+=1
EXIT /B

:total
IF %_bytes%==0 (ECHO No files processed) ELSE (ECHO %_count% matching files, %_bytes%KB)
GOTO :eof

:help
ECHO.
ECHO DTSTAMP [ADDDT]
ECHO.
ECHO Batch adding Date and Time stamp to all jpg files in the current directory.
ECHO  New file with name (original name)_DT.jpg will be generated.
ECHO.
ECHO Run command with ADDDT option to actually process jpg files, otherwise the command only list the files that will be affected.
ECHO.
ECHO !! No warranty expressed or implied !!
ECHO !! Use at your own risk             !!

Notes

  • The date time format is now by default “DD/MM/YYYY HH:MM:SS”. The format is configured by line 33. You can change it based on your need.
  • The new version will skip files that have already had the date time stamp added. If you run the script more than once, the previously stamped files (with “_DT” added in their names) will be over written.
  • If you want to change the location of the date time stamp, check out line 34. The location is specified by the string after “-gravity”. NorthWest is top left and SouthEast is bottom right, etc.

Download

If you have problem copying the script directly from above, you can download it here: DTStampV2

Posted in: Digital photography, Software on June 11th, 2010. Trackback URI
Keywords: , ,

Related Posts

Comments

  • http://www.djoh.net/inde/ Djoh

    Thanks a lot ! Exactly what I was looking for.
    I removed the need to add ADDDT and the confirmation, so it just processes all the photos, as it’s going to be used by non-tech savvy people !

  • Fighter199

    thank you very much, I followed successfuly the first how to, but this one gave me the possibility to stamp only the date, (I didn’t need/want the time stamped).
    Really appreciate.

    • http://dptnt.com/ picmax

      Please check line #33 of the script and modify as you wish.

  • Fighter199

    Yes, thank you very much.

    one more question please: How to change the output file name to have the date appended in the end.

  • Jonathan Lynch

    Hi,

    I was experimenting to make the text stand out more when the background where the text is placed is white or some bright color and came up with the following:

    convert %_inname% -gravity SouthEast -font “Digital-7-Italic” -pointsize %pointsize% -stroke black -strokewidth 8 -annotate +%pointsize%+%pointsize% %DTString% -fill white -stroke none -annotate +%pointsize%+%pointsize% %DTString% %_outname%

    This adds a black outline to the white text.

    I tried to use the -undercolor imagemagick parameter to add a background to the text but for some reason with the Digital-7-Italic font the background only applied to half the height of the text. this works for other fonts.

    Any ideas?

    Jonathan

  • Jonathan Lynch

    code to set fontsize the same for landscape or potrait orientation. (instead of lines 17-29). might save someone some time figuring out the horrible batch scripting syntax to do this :)

    FOR /F “tokens=1,2 delims= ” %%a IN (‘identify -format “%%w %%h” %_inname%’) DO SET width=%%a&set height=%%b
    if %width% GTR %height% Set /a pointsize=%width%/30
    if %width% LEQ %height% Set /a pointsize=%height%/30

    • Jonathan Lynch

      meant lines (27-29)

  • Lubelaczek

    Forgive me my ignorance… I simply copy and paste code you provided into dir that contains jpg photos. Typed “DTStampV2 ADDDT” into cmd line and it gives me this message:

    ‘CHOICE’ is not recognized as an internal or external command, operable program or batch file.
    Same message for ‘identify’. Followed by

    “no files to convert”
    Run “Convert /? for help.”

    I don’t understand what I am missing. Could you help me a little?

  • Kimberly

    I’m having a problem with the font. I get the following message after running the command prompt:

    Magick: unable to read font ‘Digital-7-Italic’ @warning/annotate.c/RenderType/862

    I switched the script to Arial but got the same message. It does the work but Magick shutdown message keeps popping up after every picture.

    I’m running Windows Vista.

    Any solution?

    Kimberly

  • http://www.imcredel.com Shane Nash

    verry nic article,i vas lookng for a way to add date to my photos

  • Debi

    Do you have a version of this that works with Windows 7?

    Thanks.

  • Arif786x

    Thank you so much. Worked a treat.

  • Msafine

    Hi, excellent tool! Thank you.
    I have a request. Is there any way to print month in 3 letters?
    Like January = JAN, February = FEB, etc?

  • Msafine

    Here is more I’ve was thinking about. In
    DTString=”%month%/%day%/%year% %hour%:%min%:%sec%

    If you use MONTH, then it will print whole month in capital.
    If you use MONTH3 or MON, then it will use abbreviated name.

  • Olli Männistö

    I immediately modified this with portrait support and added a black outline to the date. I see I’m not the only one to come up with that. Also a rather elegant use of “for” to process the command output there. I was wondering for a bit how to do that but just went with the temp file method of the original.

    Adding black outline to the text works like this:

    convert %_inname% -gravity SouthEast -font “Digital-7-Italic” -pointsize %pointsize% -stroke black -strokewidth 3 -fill white -annotate +%pointsize%+%pointsize% %DTString% %_outname%

    For some reason the example below does the annotation twice..