"Mat" an image

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
rzuris

"Mat" an image

Post by rzuris »

I want to crop an image and "mat" it against a white background. I can do this in 3 steps with piping, but I wonder if it can be reduced to 1 or 2 steps. Here's a sample that crops a rectangle with an aspect ratio of 3:5, scales the image to fit on a 3x5" background (900x1500 @ 300dpi) with a 1/4" border (750x1350), then creates a 3x5" background with the image optically centered:

convert -crop 642x1072+189+148 original.tif - | convert -geometry 750x1350 - - | convert -size 900x1500 xc:white - -geometry +75+115 -composite output.jpg

(Please ignore the fact that I'm scaling the input image upward, which will degrade its quality. This is only a test image.)

If I try to add -geometry with the -crop, then the cropped area shifts down and right. If I try to add width and height to the -geometry for the composite, it shifts the image to the lower-right corner of the composite. That's why I do the crop first, then the size geometry in the second step and the offset geometry in the third. Is it possible to combine these steps more efficiently (by eliminating piping, it may run faster)?
Post Reply