Page 1 of 1

Annotate filename without extension on Windows

Posted: 2014-07-31T08:56:50-07:00
by Demian
I've been reading documentation, StackOverflow, and these forums for a while now yet I fail to do something as simple as annotating the filename without the extension on Windows. I'm using ImageMagick-6.8.9-6-Q16-x64-dll.exe Windows binary release from the official website. Here's some related information which doesn't seem to work on my machine:
https://stackoverflow.com/questions/410 ... or-similar
http://www.imagemagick.org/Usage/windows/#filenames
http://www.imagemagick.org/Usage/annotating/

Apparently %1 is the filename with extension on Windows. %~n1 is supposed to be the filename without the extension. Neither variable works for me. I've also tried %f, %filename, %~1, and $filename with and without quotes. Nothing works.

Here's what I've tried. This works, I get a small black "test" word at the bottom of the image, as expected. Using convert instead of mogrify with proper input/output files has the exact same effect.

Code: Select all

mogrify -gravity south -annotate 0 "test" *.png
This doesn't work. Nothing is overlaid.

Code: Select all

mogrify -gravity south -annotate 0 "%1" *.png
This doesn't work. Nothing is overlaid.

Code: Select all

mogrify -gravity south -annotate 0 "%~n1" *.png

Re: Annotate filename without extension on Windows

Posted: 2014-07-31T09:23:48-07:00
by snibgo
Demian wrote:mogrify -gravity south -annotate 0 "%1" *.png
You are using this inside a BAT script file, I suppose? "%1" is the first argument to the script. When you run the script, Windows will expand the %1, so all the files will be annotated with that argument.

Perhaps you want "%t", which will be expanded by ImageMagick for each image (not once by Windows).

See http://www.imagemagick.org/script/escape.php

Re: Annotate filename without extension on Windows

Posted: 2014-07-31T10:31:24-07:00
by Demian
snibgo wrote:You are using this inside a BAT script file, I suppose?
Correct.
snibgo wrote:Perhaps you want "%t", which will be expanded by ImageMagick for each image (not once by Windows).

See http://www.imagemagick.org/script/escape.php
That is exactly what I needed. Thanks for the link too! I didn't come across that while Googling. Here's the final working script. Notice the double percentages since Windows needs to escape that character, otherwise it will annotate "t".

Code: Select all

mogrify -gravity south -annotate 0 "%%t" *.png