Add the shutter speed and Aperture value to a photo



@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"

Add the shutter speed and Aperture value to a photo.

Image Magick outputs the aperture value and shutter speed in a format that needs modifying and so the code uses some calculations.

NOTE: adding -ping speeds up the process; on a 3.11MB image it nearly halved the process time.