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