ImageMagick 合成在合成前调整图像大小
我正在使用 ImageMagick 的合成命令将一张较小的图像合成到较大的图像上。生成的图像应与背景图像(较大的图像)大小相同。此外,我希望较小的那个始终具有相同的尺寸。
目前我有这样一个简单的调用:
composite -gravity SouthWest watermark.png photo.jpg photo.jpg
问题是我为不同的照片获得不同大小的水印,并且我不知道如何将其设置为固定大小。我尝试了 -resize、-geometry 和 -size 选项,但它们都改变了结果图像的大小,而不是水印。
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 the 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了类似的问题,并使用复合命令尝试了各种不同的选项以尝试使其正常工作。最终我不得不切换到使用转换命令,并且能够使用重力来调整它的大小:
-draw 的数字参数是左,顶,宽度,高度。请参阅 http://www.imagemagick.org/script/command-line -options.php?#draw。因此,该解决方案不再使用复合命令,但希望能够满足您的需求。
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:
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!
我从 ImageMagick 手册中的一个小注释中找到了答案,该注释说
-resize '1x1<'
本质上是一个无操作(和短路)调整大小操作。因此,如果我有一个 1200x1200 image.jpg,并用 600x600copyright.png 覆盖它,则使用以下命令:
我的图像将根据copyright.png 调整大小为 600x600。
但是,如果我执行以下操作:
我的输出图像将保留其原始大小 1200x1200。
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:
my image gets resized to 600x600 as per the copyright.png.
However, if I do the following:
my output image retains its orginal size of 1200x1200.