I'm using ImageMagick's composite command to compose one smaller image over larger one. The resulting image should be of size of the background image (the larger one). Additionally I want the smaller one to be always of th开发者_JAVA百科e same size.
Currently I have such a simple invocation:
composite -gravity SouthWest watermark.png photo.jpg photo.jpg
The problem is that I get different sizes of watermark for different photos and I don't know how to set it to be fixed size. I tried -resize, -geometry and -size options but all of them change size of resulting image and not the watermark.
I had a similar problem and tried all sorts of different options with the composite command to try to get it to work. Eventually I had to switch to using the convert command and was able to get it to resize with gravity using:
convert photo.jpg -gravity SouthWest -draw "image Over 0,0,200,200 watermark.png" photo.jpg
The numeric parameters for -draw are left,top,width,height. See http://www.imagemagick.org/script/command-line-options.php?#draw. So this solution no longer uses the composite command but hopefully gives you what you want.
Hurraaay!
I have found the answer from a little note in the ImageMagick manual that says -resize '1x1<'
is essentially a no-op (and SHORT-CIRCUIT) for the resize operation.
So, if I have a 1200x1200 image.jpg and I overlay it with a 600x600 copyright.png, using this command:
composite -dissolve 50% -gravity center image.jpg copyright.png result.jpg
my image gets resized to 600x600 as per the copyright.png.
However, if I do the following:
composite -resize '1x1<' -dissolve 50% -gravity center image.jpg copyright.png result.jpg
my output image retains its orginal size of 1200x1200.
精彩评论