"Mat" an image
Posted: 2007-04-09T16:41:56-07:00
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)?
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)?