Problems appending output filenames

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
griffindodd

Problems appending output filenames

Post by griffindodd »

I'm struggling writing a BAT file in windows to make make new resized images from my source files and have them copied to a new directory with a naming convention...

e.g. a source file of

files\uploads\a.jpg

Needs to be resized and saved to a new directory with a new name, one for a thumbnail and one for a resized version of the image. The resized image needs to append the filename with a suffix 'PICTURE' and the thumbnail needs to append the filename with prefix 'PICTURE' and suffix 'T'...

e.g output looks like this

files\converted\PICTUREa.jpg
files\converted\PICTUREaT.jpg

I have been trying to use MOGRIFY but have been banging my head against a wall trying to work out the renaming.

Any help gladly appreciated.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Problems appending output filenames

Post by Bonzo »

This should help you out ( in this case I drop the photo over the icon ):

Code: Select all

:: Resize the photo and create a thumbnail
convert.exe %1 -auto-orient ( +clone -thumbnail 500x300 -write "C:\Users\Anthony\Desktop\Rubble_photos\%~n1.jpg" +delete ) -thumbnail 125x75 -unsharp 1.5x1+0.7+0.02 "C:\Users\Anthony\Desktop\Rubble_photos\th_%~n1.jpg"
griffindodd

Re: Problems appending output filenames

Post by griffindodd »

I had a problem following your code as I trying to write a script I can automate in a bat file, I tried this but I am getting nothing...

set var=folder1
echo %var%
mogrify -thumbnail 600x450 -write "uploads\%var%\%~n1.jpg") -thumbnail 100x100 -unsharp 1.5x1+0.7+0.02 "converted\%var%\THUMB_%~n1.jpg"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems appending output filenames

Post by fmw42 »

I know nothing about Windows, but if you have not looked at http://www.imagemagick.org/Usage/windows/, it could be useful.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Problems appending output filenames

Post by anthony »

Please, add appropriate line breaks to commands. You can even to this in DOS BAT scripts!!!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Empire
Posts: 1
Joined: 2013-09-02T19:27:18-07:00
Authentication code: 6789

Re: Problems appending output filenames

Post by Empire »

In windows, to save every png image with it's own filename appended with '_red'

Code: Select all

convert ( *.png -alpha extract ) -background red -alpha shape ^
-set filename:f %t_red.%e +adjoin %[filename:f]
 
More specifically, this changes the images' color to red. Seems like it sets the entire filename to a variable "filename:f". There, %t is the filename text and %e is the extension.

Different from the sources (in Windows), parentheses don't need to be escaped and the source and destination of the output filename don't need to be enclosed in quotes. Also, the ^ character is used for line continuation.

Credit:
Color change - http://stackoverflow.com/a/14320328/1552045
Output filename - http://www.imagemagick.org/Usage/files/
Post Reply