I want to convert a group of files, but not overwrite the existing file. How can I use mogrify to specificy the final file format? For example, firstpic.png -> firstpic-thumbnail.png, secondpic.png -> secondpic-thumbnail.png, etc.
gm mogrify -size 150x150 *.png -resize 150x150 +profile "*" "%f-thumbnail.png"
Is there any way to do this?
I don't know if there's a way to specify output file format from mogrify but I would use convert
with simple bash loop instead:
for f in *.jpg;
do
convert "$f" -resize 150x150 +profile "*" "${f%.jpg}-thumbnail.jpg";
done;
Or if you really want to use mogrify
you can use -output-directory
(more on this option here) to put new files into separate directory and then take care of renaming:
mkdir tmp;
gm mogrify -output-directory tmp -size 150x150 -resize 150x150 +profile "" "*.jpg";
for f in tmp/*.jpg;
do
mv "$f" "${f%.jpg}-thumbnail.jpg";
done;
mv tmp/* .;
rm -rf tmp;
I like the first method better ;)
If the output format (extension) is different from the input format, the files won't get overwritten. If they are the same, you can use this trick, that makes them appear to be "different" for this purpose but are really the same but differ in the case of the extension:
gm mogrify -resize 150x150 -format PNG +profile "*" *.png
EDIT:
I don't know of a facility within "mogrify" to rename the output files other than specifying a different directory or a different extension. So fragphace's answer is correct; you will need to use a script to rename them. In combination with my answer:
gm mogrify -resize 150x150 -format PNG +profile "*" *.png
for file in *.PNG
do
basename=`echo $file | sed -e "s/.PNG//"`
mv $basename.PNG $basename-thumbnail.png
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With