Multiple operations... I'm lost!

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
Flaver-D
Posts: 19
Joined: 2015-05-21T12:27:39-07:00
Authentication code: 6789

Multiple operations... I'm lost!

Post by Flaver-D »

Hi again!
I'm slaving on what would be a simple piece of code but for some reason I'm completely lost in my Windows command prompt!

I'm trying to make a small script that will take a square picture, resize it to 11x11 inch at 300DPI (which is 3300 pixels), invert the colors (negative) and crop it back to 8½x11 inch (2500x3300 pixels) and save it as an MPC.
Then take the original image, add a 10 pixel border around it on the outside and save it as an MPC also.
Once I have those two sets of images, I just want to composite the two image using center gravity and save the whole thing as a PNG...

So far, this is what I cobbled up and its failing miserably!

Code: Select all

convert -resize 3300x3300 -filter cubic -negate -crop 2500x3300 -blur 10 *.jpg *.mpc
convert *.jpg -border 10x10 -bordercolor "#000000" *Border.mpc 
composite -gravity center *.mpc *Border.mpc *.png
Anybody know what the heck I'm doing wrong?
François
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Multiple operations... I'm lost!

Post by glennrp »

Using wildcards as the output file won't work. I believe you are thinking of "mogrify" instead of "convert"; in this case just use the "-format png" or "-format mpc" instead of specifying an output file. You could distinguish between the Border and unbordered versions by using -format MPC for one of them.

Code: Select all

mogrify -resize 3300x3300 -filter cubic -negate -crop 2500x3300 -blur 10 -format mpc *.jpg
mogrify -border 10x10 -bordercolor "#000000" -format MPC *.jpg
There's no "mogrify" version of composite, so you'd need to do that in a loop:

Code: Select all

for x in *.jpg
do
root=`echo $x | sed -e s/.jpg//`
composite -gravity center $root.mpc $root.MPC $root.png
done
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Multiple operations... I'm lost!

Post by GeeMack »

Flaver-D wrote:So far, this is what I cobbled up and its failing miserably!

Code: Select all

convert -resize 3300x3300 -filter cubic -negate -crop 2500x3300 -blur 10 *.jpg *.mpc
convert *.jpg -border 10x10 -bordercolor "#000000" *Border.mpc 
composite -gravity center *.mpc *Border.mpc *.png
Anybody know what the heck I'm doing wrong?
I'm not exactly sure what you're trying to accomplish here, but it looks like you might want something like this...

Code: Select all

convert *.jpg -filter cubic -resize 3300x3300 -gravity center -extent 2500x3300 -negate -blur 10 img%04d.mpc

convert *.jpg -bordercolor #000000 -border 10x10 border%04d.mpc

convert img*.mpc null: border*.mpc -gravity center -layers composite output%04d.png
I run those three command lines from a Windows 7 64 cmd prompt with IM7 and get no errors.

The first "convert" takes all the JPGs in the directory, resizes them all to 3300x3300 using the "cubic" filter, crops them all (using extent) to 2550x3300, negates them all, blurs them all, then saves them as MPC sets with names like img0001.mpc, img0001.mpc, etc.

The second "convert" takes all the JPGs, adds a 10x10 black border to each, and saves them as MPC sets with names like border0000.mpc, border0001.mpc, etc.

The third "convert" takes those two bunches of MPC files, composites (using layers) each border*.mpc image onto the center of its companion img*.mpc image, and saves them all as output0000.png, output0001.png, etc.

That's doing pretty much what you seem to be asking for.
Flaver-D
Posts: 19
Joined: 2015-05-21T12:27:39-07:00
Authentication code: 6789

Re: Multiple operations... I'm lost!

Post by Flaver-D »

That's exactly it!
I did manage to do something late last night using mogrify but the composite part was really annoying me as all I could get was some odd transparency effect that just didn't work.

Now that I got the basic gist of it, I can tweak it all so I can get the best effect for my project.
All I need to do now if make it work in a batch file.
Thanks!
François
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Multiple operations... I'm lost!

Post by fmw42 »

This should work for a single input images. To do more than that, you would need to write a script loop over the directory of images you want to process.

Unix syntax.

Code: Select all

convert input \
\( -clone 0 -bordercolor "#000000" -border 10x10 \) \
\( -clone 0 -filter cubic -resize 3300x3300 -negate -crop 2500x3300 +repage -blur 10 \) \
-gravity center -compose over -composite result
Please always provide your IM version and platform, since syntax differs.


Note proper IM 6 syntax has the input image before any settings or operators and settings before operators. See http://www.imagemagick.org/Usage/basics/#cmdline

Also you will get the best blur results by using the RadiusxSigma format with radius=0, so -blur 0xSigma. Your -blur 10 is just setting the radius to 10 and I do not know what sigma is being used with that structure. So it may not be a good gaussian approximation. By using 0xSigma. The radius is determined automatically to optimize the guassian shape.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Multiple operations... I'm lost!

Post by GeeMack »

Flaver-D wrote:Now that I got the basic gist of it, I can tweak it all so I can get the best effect for my project.
All I need to do now if make it work in a batch file.
In a Windows batch file you'll need to double all the percent signs, so make "img%04d.jpg" into "img%%04d.jpg". Also, I'm in the bad habit of leaving out the quote marks when I use hex numbers for colors, like #000000. It's probably a better idea to use "#000000" in most cases. In Windows it usually shouldn't matter, but if you port a script over to *nix system, that unquoted pound sign will mess it up.

Keep in mind the "%04d" in the file names in my examples will make sequential numbers with 4 digits starting at 0000. If you are certain to have less than a thousand images you could use something like "img%03d.jpg" for 3 digit numbers. If you want the numbering to start somewhere other than 0, like to have the first output image start at number 0023, you can add the command "-scene 23" just before the output image name.

Also, converting a directory full of images using a wildcard asterisk, like "convert *.jpg...", will use all the JPGs in the directory, but if you're trying to use an image type with more than one layer, like GIFs or PSDs, you may need to work the commands into a loop because... If you have two 4 layer GIFs and two 2 layer GIFs for example, starting with "convert *.gif..." will put 12 images into the initial image stack, so a command like...

Code: Select all

convert *.gif -resize 200x200 output%04d.jpg
... will create 12 JPGs named "output0000.jpg" through "output0011.jpg" because it's processing all the layers in all the files.

Hope all that didn't give you more confusion than help. ;)
Flaver-D
Posts: 19
Joined: 2015-05-21T12:27:39-07:00
Authentication code: 6789

Re: Multiple operations... I'm lost!

Post by Flaver-D »

Just what I did...

BTW, I'm running IM 6.9.2-10 Q16 x64 on Windows 10
François
Post Reply