Annotate filename without extension on Windows

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
Demian
Posts: 9
Joined: 2012-01-18T10:00:19-07:00
Authentication code: 8675308

Annotate filename without extension on Windows

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Annotate filename without extension on Windows

Post 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
snibgo's IM pages: im.snibgo.com
Demian
Posts: 9
Joined: 2012-01-18T10:00:19-07:00
Authentication code: 8675308

Re: Annotate filename without extension on Windows

Post 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
Post Reply