Combining crop and compose in one line.

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
mountainman

Combining crop and compose in one line.

Post by mountainman »

I've created a bash script to copy skinnier and skinnier segments from the center of one image, and paste them over another image. This creates a "barn door wipe" effect for use in a video. The relavant portion of the script is:

Code: Select all

convert $startimage  -gravity center  -crop $percent%x100%  temp.png 
composite -gravity center temp.png $endimage -quality $qual frame$counter$ext
This works as I had hoped. However, since this is inside a loop the fact that it first writes the cropped image to a temp file (a png image) each time is inefficient. What I'd like to do is combine this all into one statement and skip writing the temp file. In looking at the documentation, I found the usage example for composites. However, in the example given the image created with the convert statement is used as the background, and I want this to be the foreground. I've played around with several different ways I thought might work with this, but so far no luck. Can anyone here suggest a way to do this? Thanks!
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Combining crop and compose in one line.

Post by el_supremo »

I think this will do it:

Code: Select all

convert -gravity center $endimage \( $startimage  -gravity center  -crop $percent%x100% +repage \) -composite -quality $qual frame$counter$ext
Note that when compositing with "convert" the two input files are specified in the opposite order than what the "composite" program requires.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
mountainman

Re: Combining crop and compose in one line.

Post by mountainman »

Perfect! Thanks!
Post Reply