In graphicsmagick, how can I specify the output file for a large number of files?

I want to convert a group of files, but not overwrite the existing file. How to use mogrify for a specific 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?

+4
source share
2 answers

I don't know if there is a way to specify the output file format from mogrify, but I would use convertwith a simple bash loop:

for f in *.jpg; 
do 
    convert "$f" -resize 150x150 +profile "*" "${f%.jpg}-thumbnail.jpg"; 
done;

mogrify, -output-directory ( ), , :

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;

;)

+3

() , . , , "" , , :

gm mogrify -resize 150x150 -format PNG +profile "*" *.png

EDIT:

, "mogrify" , . , ; script, . :

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
+2

Source: https://habr.com/ru/post/1547191/


All Articles