JOHN
JOHN

Reputation: 1511

How to modify this script to add date instead of date and time to the picture?

I have come across this useful program to add date and time to photos. How can I modify the bat file so that it only adds date but not date time?

e.g. 2017:12:10 instead of 2017:12:10 10:10:02

@echo off & cls
rem enable variables referencing themselves inside loops
SetLocal EnableDelayedExpansion

rem optional settings
set fontcolor=#FFD800
set fontoutlinecolor=#000000
set fontstyle="Arial-Bold"

rem create a new folder where the stamped images will be placed
mkdir stamped

rem loop through all jpg png jpeg and gif files in the current folder
for /f "delims=" %%a in ('dir /b /A:-D /T:C "%cd%\*.jpg" "%cd%\*.png" "%cd%\*.jpeg" "%cd%\*.gif"') do (
    rem retrieve image date and time
    SetLocal EnableDelayedExpansion
    for /f "tokens=1-2" %%i in ('identify.exe -ping -format "%%w %%h" "%cd%\%%a"') do set W=%%i& set H=%%j

    rem retrieve image timestamp to perform size and distance calculations on
    SetLocal EnableDelayedExpansion
    for /f "tokens=1-2 delims=" %%k in ('identify -format "%%[EXIF:DateTimeOriginal]" "%cd%\%%a"') do set timestamp=%%k

    rem set timestamp to no timestamp if there is no timestamp
    if "!timestamp!" == "" (
        set timestamp=No timestamp
    )

    rem print some information about the process
    echo %%a is !W! x !H! stamp !timestamp! ...

    rem set timestamp size to a fourth of the screen width
    set /A timestampsize = !W! / 3

    rem set timestamp offset distance from side of the screen
    set /A timestampoffset = !W! / 20

    rem set timestamp outline relative size
    set /A outlinewidth = !W! / 600

    rem echo !timestampsize! !timestampoffset!

    rem create a custom image with the timestamp with transparent background and combine it with the image
    convert.exe ^
    -verbose ^
    -background none^
    -stroke !fontoutlinecolor! ^
    -strokewidth !outlinewidth! ^
    -font !fontstyle! ^
    -fill !fontcolor! ^
    -size !timestampsize!x ^
    -gravity center label:"!timestamp!" "%cd%\%%a" +swap ^
    -gravity southeast ^
    -geometry +!timestampoffset!+!timestampoffset! ^
    -stroke !fontoutlinecolor! ^
    -strokewidth !outlinewidth! ^
    -composite "%cd%\stamped\%%a"

    endlocal
    endlocal
    echo.
)
endlocal
echo Complete!
pause

The original file place: https://nirklars.wordpress.com/2015/04/25/add-scaled-timestamps-to-photos/

Upvotes: 1

Views: 571

Answers (2)

GeeMack
GeeMack

Reputation: 5385

You can get just the date from the EXIF time stamp by editing this line...

for /f "tokens=1-2 delims=" %%k in ('identify -format "%%[EXIF:DateTimeOriginal]" "%cd%\%%a"') do set timestamp=%%k

Change that line to this...

for /f "tokens=1-2 delims= " %%k in ('identify -format "%%[EXIF:DateTimeOriginal]" "%cd%\%%a"') do set timestamp=%%k

That way you're using a space as a delimiter with "delims= " instead of "delims=". Then your variable "%k" only reads the output of the "identify" command up to the first space, which is just the date part. Then it sets your "%timestamp%" variable to that value and continues as before.

Upvotes: 1

Mark Setchell
Mark Setchell

Reputation: 207435

I don't speak that awful Windows BATCH language monstrosity, but I suspect you need to change the line:

for /f "tokens=1-2 delims=" %%k in ('identify -format "%%[EXIF:DateTimeOriginal]" "%cd%\%%a"') do set timestamp=%%k

to only take the first token, instead of the first two:

for /f "tokens=1 delims=" %%k in ('identify -format "%%[EXIF:DateTimeOriginal]" "%cd%\%%a"') do set timestamp=%%k

If that doesn't work, and anybody who doesn't understand ImageMagick but does understand Windows BATCH, the following command:

identify -format "%%[EXIF:DateTimeOriginal]" someImage.jpg

produces this:

2013:03:09 08:59:50

Upvotes: 0

Related Questions