Add scaled timestamps to photos using ImageMagickPosted: 25/04/2015 | |
Here is one way to add timestamps quickly to lots of photos using open source tools and a script.
The image editing is done using ImageMagick convert.exe and identify.exe
ImageMagick is a free to use open source collection of command line tools for image editing, identifying, manipulation and much more.
This script will go through all JPG, JPEG, GIF and PNG files inside the current folder, make copies of them in a separate folder and add date and time saved (burned) into the image. The operation is lossy hence it only modifies copies of the files. Date and time is retrieved from the metadata tag Exif.Image.DateTimeOriginal. If the images lack this tag they will be stamped “No timestamp”.
The timestamp font size and placement on the photo will scale in percentage according to the width and resolution of the photo.
If you want to change colors or such you will need to edit the script manually. Here are some examples of photos I’ve taken with added timestamps:
If these kind of timestamps are good enough for you, you’ve found the right post!
Option a) – quick
2. Extract all files in the folder where you keep the images that you wish to add timestamps to
3. Double click on add timestamps.bat to start the process.
A black window should pop up showing the image conversion process in ImageMagick.
4. When done you should see a folder named stamped with copies of the files with added timestamps!
Option b) – manual
1. Download ImageMagick from the windows portable edition here and place convert.exe and identify.exe in the same directory where you place the script. Alternately you can use the files supplied in the download above.
2. Copy and paste the code from below into your favorite plain text editor like notepad, notepad2 or notepad++
3. Save it with whichever name you prefer as long as you end the name with the file extension .bat for example add timestamps.bat
4. Double click on the bat file to start the process!
Batch script to copy and paste
@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
I also wrote a VBScript version of this operation as well but It would have a lot of black windows popping up being quite annoying.
Unfortunately hiding windows gets trickier when using VBScript when you also need to retrieve the return value from command line utilities.