Mogrify & stamp exif data

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
moltubakk
Posts: 1
Joined: 2011-09-04T06:37:23-07:00
Authentication code: 8675308

Mogrify & stamp exif data

Post by moltubakk »

I've been trying to find a way to batch resize jpeg images and at the same time stamp time, date and filename. My solution works, but I'ts not perfect, so I would really appreciate some help!

My jpg files are located in a (linux) folder structure like this: /YYYY/YYYYMM/jpg files

My solution is a two-step solution:

Code: Select all

exiftool -r -overwrite_original '-UserComment<${filename}' /home/bjornar/FOTOTEST/
(to include the filename of each jpg in the folder structure as a UserComment)

Code: Select all

mogrify -resize 1920x1080 -fill red -gravity SouthWest -font URWGothicBook -pointsize 60 -annotate +0+5 "date: %[exif:DateTimeOriginal] %[exif:UserComment]" /home/bjornar/FOTOTEST/*/*/*
(reduce the resize all the photos in my file structure to fit my tv screen, add the original date&time, and user comment).

However:
1. When the filename appears in the picture it is presided by the text “ASCII…” I would like to get rid of this text, but so far I have not been able to figure out how.
2. Exactly what exif tags can be put into my mogrify command line like this? I have not been able to find any pattern to this.
3. Is there an easier way to achieve this?

In advance - thanks a lot for any help!
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Mogrify & stamp exif data

Post by Bonzo »

I use convert for everything as there are more options :D

One of your problems is you are not escaping the % - check out: http://www.imagemagick.org/Usage/windows/

Image

Here is a batch file I wrote to produce the image above ( you could use this as a base for your code ):

Code: Select all

:: Do not display the code while running
@ECHO OFF

:: Select the F number from the EXIF data and set the FNumber variable
FOR /F %%x IN ('identify -ping -format "%%[EXIF:FNumber]" %1') DO SET FNumber=%%x

:: Set the FNumber1 variable to the F number value
:: Image Magick returns the F number in the format of 700/100 or 40/10
FOR /F %%x IN ('convert xc: -ping -format "%%[fx:%FNumber%]" info:') DO SET FNumber1=%%x

:: Set the value of the shutter variable to the shutter speed
:: Select the shutter speed from the EXIF data
:: Image Magick returns the shutter speed in the format of 810/100
FOR /F %%x IN ('identify -ping -format "%%[EXIF:ShutterSpeedValue]" %1') DO SET shutter=%%x

:: Format the speed to 8.1 and set the speed variable
FOR /F %%x IN ('convert xc: -ping -format "%%[fx:%shutter%]" info:') DO SET speed=%%x

:: Calculate the speed in seconds using the power of 2 and save it in the shutterspeed variable
FOR /F %%x IN ('convert xc: -ping -format "%%[fx:floor((pow(2,%speed%)))]" info:') ^
 DO SET shutterspeed=%%x

:: Add the F number and shutter speed to the image and save as exif_OriginalImageName
convert %INPUTFILE% ^
-pointsize 16 -fill black -gravity northwest ^
-annotate +10+5 "Aperture: F%FNumber1% Shutter speed: 1/%shutterspeed% sec" "%~p1EXIF_%~n1.jpg"  
There are some more batch file examples on my website: http://www.rubblewebs.co.uk/imagemagick/batch.php
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Mogrify & stamp exif data

Post by anthony »

moltubakk wrote:My solution is a two-step solution:

Code: Select all

exiftool -r -overwrite_original '-UserComment<${filename}' /home/bjornar/FOTOTEST/
(to include the filename of each jpg in the folder structure as a UserComment)

Code: Select all

mogrify -resize 1920x1080 -fill red -gravity SouthWest -font URWGothicBook -pointsize 60 -annotate +0+5 "date: %[exif:DateTimeOriginal] %[exif:UserComment]" /home/bjornar/FOTOTEST/*/*/*
As you are resizing the image you should not need to use the 'lossless step'. IM does know the filename (without the directory component, though it can output that too.)

Code: Select all

mogrify -resize 1920x1080 -fill red -gravity SouthWest -font URWGothicBook -pointsize 60  \
            -annotate +0+5 "date:%[exif:DateTimeOriginal] %f"  /home/bjornar/FOTOTEST/*/*/*
If you want you can also set the normal JPEG user comment at the same time. using -set comment "..."
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply