I wrote a dos batch file which extracts the date and time of a jpg file and adds it to it - in the lower right corner. I wrote the following script (if you execute it, for all .jpg files in the directory where the script resides, a copy will be created which contains the date and time - the original image will not be modified).
The batch file does basically nothing for .jpg files which do not have EXIF information for date and time and I did not test it on files with small resolution. I intended the batch file to be used to label pictures taken with a digital camera. I tested the file using Win7 and am not sure if the syntax is valid for older version of Windows.
Here's an example:
Code: Select all
SETLOCAL ENABLEDELAYEDEXPANSION
rem echo off
set ptsize=70
set x=0
set y=0
set /a dx1=%x%+1
set /a dy1=%y%+1
set /a dx2=%x%+2
set /a dy2=%y%+2
for %%f in (*.jpg) do (
rem Read out date of .jpg file (from EXIF info)
identify -format \n%%[EXIF:DateTime] %%f > curdate.txt
rem Read date from curdate.txt
for /f "usebackq eol=; tokens=1,2,3,4,5,6 delims=: " %%i in ("curdate.txt") do (
@set Year=%%i&@set Month=%%j&@set Day=%%k&@set Hours=%%l&@set Minutes=%%m&@set Secs=%%n
)
set Text=!Day!.!Month!.!Year! !Hours!:!Minutes!:!Secs!
convert -size 800x150 xc:transparent -pointsize %ptsize% -gravity southeast ^
-fill black -draw "text %x%,%y% '!Text!'" ^
-fill white -draw "text %dx2%,%dx2% '!Text!'" ^
-rotate 180 ^
trans_stamp.png
convert -size 800x150 xc:black -threshold 100%% +matte -pointsize %ptsize% -gravity southeast ^
-fill white -draw "text %x%,%y% '!Text!'" ^
-fill white -draw "text %dx2%,%dy2% '!Text!'" ^
-fill black -draw "text %dx1%,%dy1% '!Text!'" ^
-blur 2x2 ^
-rotate 180^
mask_mask.bmp
convert %%f -rotate 180 %%f.tmp.jpg
composite trans_stamp.png %%f.tmp.jpg mask_mask.bmp _%%f.rot.FP_Converted.jpg
convert _%%f.rot.FP_Converted.jpg -rotate 180 _%%f.FP_Converted
del %%f.tmp.jpg
del _%%f.rot.FP_Converted.jpg
rem Delete variables
FOR %%a in (Year Month Day Hours Minutes Secs Text) do @SET %%a=
del trans_stamp.png
del mask_mask.bmp
)
rem Delete variables
FOR %%a in (x y dx1 dy1 dx2 dy2) do @SET %%a=
ren _*.FP_Converted *.
:end
ENDLOCAL
The first convert creates a stamp.
The second convert creates a mask.
I then just want to overlay the images. However, since -gravity does not affect the mask in composite (see http://www.imagemagick.org/Usage/compose/#mask), I thought it to be a good idea to rotate the images, compose them, and rotate them back.
That is what I do with the convert -rotate 180
Finally my problem:
- - The batch file is quite slow (due to the many calls to convert). I'd like it to be faster.
- I do not like that I create temporary files. I'd rater combine the last three commands (line 41, 42 and 43) to one command. However, I could not find a solution for this.
- For Images not taken in portrait mode (i.e. not landscape) the label will be in the upper right corner. I'd like it to be in the lower right corner...
blackno666