Using the Filename as Text on the image.

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?".
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Using the Filename as Text on the image.

Post by Bonzo »

There are some batch file examples on my website: http://www.rubblewebs.co.uk/imagemagick/batch.php

You probably want to do something based on this:

Code: Select all

::Turn of displaying the code on the screen
@echo off

:: Read all the jpg images from the directory, resize them, add some text and save as a png in a different directory
for %%f in (%1\*.jpg) do ( convert "%%f" -resize 200x200 -pointsize 18 -fill black ^
-gravity northwest -annotate +0+0 "Some text" "%2\%%~nf.png" )

::This batch file was named resize.bat and called using "resize path\to\original\ path\to\save"
I am busy doing PC jobs for the wife at the moment :( and can not spend any time on this until next week.
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Using the Filename as Text on the image.

Post by Drarakel »

If you want to drop a directory (with subdirectories) onto the batch file, try this:

Code: Select all

@ECHO OFF
SET height=60
FOR /R %1 %%i IN (*.*) DO ( 
ECHO Processing "%%i"...
convert "%%i" -background white ( -size 1x%height% xc:white ^) -append ^
  ( -size x%height% -fill black label:"%%~ni" ^) ^
  -gravity southeast -compose over -composite ^
  ( -size x%height% -fill black label:"Protected Document - Attorney Eye's Only" ^) ^
  -gravity southwest -compose over -composite ^
  "%%i"
)
pause
Of course the right height value depends on your set of images. Consider that in the above example, one label will 'erase' the other label if the images are too narrow.
And most important: Be very careful at first, as this will overwrite all of your images! (And if you call the batch without an argument, it will change all the images in the working directory.) So, first test with unimportant copies.
Post Reply