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

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
muri
Posts: 15
Joined: 2017-01-17T05:09:01-07:00
Authentication code: 1151

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

Post 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.
Last edited by muri on 2017-01-17T10:49:14-07:00, edited 1 time in total.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

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

Post 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.
muri
Posts: 15
Joined: 2017-01-17T05:09:01-07:00
Authentication code: 1151

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

Post 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.
Post Reply