Hi,
I'm a new user (version 7.0.7-8 Q16 x64 2017-10-14) and I've read the user guide and searched online without success in getting this done. The user guide talks about mogrify and convert, as does most of the online discussion, but the only Imagemagick executable I have is magick.exe, and the options seem to be different and give errors.
I want to resize by 50% a folder of files and output them with the same filenames but with a prefix, like this:
example1.png --> small_example1.png
example2.png --> small_example2.png
etc.
Could someone please point me in the right direction to do this?
Apologies if this question has already been answered.
Cheers,
Batch Resize and Output with Same Filename with a Prefix
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Batch Resize and Output with Same Filename with a Prefix
In IM 7 magick is the same as convert. But in IM 7, you have to preface the other tools with magick. So for mogrify, you need to use magick mogrify. mogrify will process a whole folder of images, but it will only change the suffix. So you cannot add a prefix. Thus you must write a script loop over each image in the folder and use magick to resize the file and add a prefix to the output name from the input name.
So your script loop would be over the following command:
Where you need to get the name and suffix of the file and then append to the name and add the suffix back again for the output.
You can get the input name and suffix from
magick image.suffix -format "%t" info:
magick image.suffix -format "%e" info:
See http://www.imagemagick.org/script/escape.php
Scripting is OS dependent. You seem to be on Windows and I am using a Mac so unix shell scripting. So I will not be able to help with batch scripting on Windows.
In Unix syntax, this would be:
So your script loop would be over the following command:
Code: Select all
magick.exe image.suffix -resize 50% newimage.suffix
You can get the input name and suffix from
magick image.suffix -format "%t" info:
magick image.suffix -format "%e" info:
See http://www.imagemagick.org/script/escape.php
Scripting is OS dependent. You seem to be on Windows and I am using a Mac so unix shell scripting. So I will not be able to help with batch scripting on Windows.
In Unix syntax, this would be:
Code: Select all
cd to directory of images
list=$(ls *.png)
for img in $list; do
name=$(magick $img -format "%t" info:)
suffix=$(magick $img -format "%e" info:)
magick $img -resize 50% "small_${name}.suffix"
done
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Batch Resize and Output with Same Filename with a Prefix
From the Windows command prompt, if you want to resize all the PNG files in the current directory to 50%, a command like this will do exactly that...
Code: Select all
for %I in ( *.png ) do magick "%I" -set filename: "small_%t" -resize 50% "%[filename:].png"