Page 1 of 1

Multiple commands to compress / Bash "Keep file name" / rotate 45 transparency

Posted: 2017-01-17T05:26:32-07:00
by muri
Hello,
I need to edit multiple files in a folder.
The single commands for one file I have already.
Now I need this for all files in a folder.
The files must be in a new folder.
The files should retain their filenames.

The commands for one file:

Code: Select all

convert 001.jpg -gravity Center -crop 95x95+0+0 -resize 100x100 +repage ../new-one-90/001.png

Code: Select all

convert ../new-one-90/001.png \( -size 100x100 xc:none -fill white -draw "circle 49.5,49.5 48,1" \) -compose copy_opacity -composite ../new-one-90/001.png

Code: Select all

convert ../new-one-90/001.png -rotate 90 ../new-one-90/001.png
Please help.

Re: Multiple commands to compress / Bash "Keep file name"

Posted: 2017-01-17T08:40:38-07:00
by GeeMack
muri wrote: 2017-01-17T05:26:32-07:00I need to edit multiple files in a folder.
The single commands for one file I have already.
Now I need this for all files in a folder.
The files must be in a new folder.
The files should retain their filenames.
If I understand your requirements correctly, you should be able to do all that with a single command. Using ImageMagick 6.7.7 in a bash shell I can do this...

Code: Select all

convert *.jpg -set filename:f "../new-one-90/%[t]" \
   -gravity Center -crop 95x95+0+0 -resize 100x100 +repage null: \
   \( -size 100x100 xc:none -fill white -draw "circle 49.5,49.5 48,1" \) \
   -compose copy_opacity -layers composite -rotate 90 "%[filename:f].png"
That appears to accomplish the entire process of your three separate commands, and runs it on every JPG in the directory. It will bring in all the *.jpg images, crop and resize them, create another image of a white circle for a mask, composite that mask on all the other images, rotate them all 90°, and output the results as PNG files to another directory.

Re: Multiple commands to compress / Bash "Keep file name"

Posted: 2017-01-17T10:47:18-07:00
by muri
That's great!

Many thanks GeeMack.

The source images are somewhat out of round, so it takes special attention, or more precise commands (first "-gravity").

Here I have a summarized command for rotate 45 degrees with transparency PNG.

Code: Select all

convert *.jpg -set filename:f "../new-one-45/%[t]" \
   -gravity Center -crop 95x95+0+0 -resize 100x100 +repage null: \
   \( -size 100x100 xc:none -fill white -draw "circle 49.5,49.5 48,1" \) \
   -compose copy_opacity -layers composite -background transparent -rotate 45 +repage \
   -gravity Center -crop 100x100+0+0 -resize 100x100 +repage "%[filename:f].png"
One problem is the PNG offset, which occurs when turning 45 degrees. "+repage" is helpfull.