Image processing 使用ImageMagick自动调整大小覆盖两幅图像
使用ImageMagick叠加图像时,是否有方法根据背景大小自动调整叠加图像的大小?我现在正在使用以下代码: 复合叠加.jpeg背景.jpeg结果.jpegImage processing 使用ImageMagick自动调整大小覆盖两幅图像,image-processing,image-manipulation,imagemagick,Image Processing,Image Manipulation,Imagemagick,使用ImageMagick叠加图像时,是否有方法根据背景大小自动调整叠加图像的大小?我现在正在使用以下代码: 复合叠加.jpeg背景.jpeg结果.jpeg 问题是有时叠加和背景的大小不同,我想相应地调整叠加的大小(保持纵横比)并将其放置在中心。有什么方法可以做到这一点吗?首先,叠加和背景的大小不必相同,合成图就可以工作。例如,给定以下两个图像: sydney.png(352x288): jet2.png(128x129): 请尝试以下命令: convert -size 352x288 -c
问题是有时叠加和背景的大小不同,我想相应地调整叠加的大小(保持纵横比)并将其放置在中心。有什么方法可以做到这一点吗?首先,叠加和背景的大小不必相同,合成图就可以工作。例如,给定以下两个图像: sydney.png(352x288): jet2.png(128x129): 请尝试以下命令:
convert -size 352x288 -composite sydney.png jet2.png -geometry 64x64+176+144 -depth 8 test.png
convert -size 352x288 -composite sydney.png jet2.png -geometry 32x32+176+144 -depth 8 test.png
指定输出图像的尺寸-size
指定前景的尺寸和位置-几何图形
#!/bin/bash
if [ -z "$3" ]
then
echo "usage: $0 background.png foreground.png output.png"
exit 1
fi
bg_size=`identify -format '%wx%h' "$1"`
convert -size $bg_size -composite "$1" "$2" -geometry $bg_size+0+0 -depth 8 "$3"
因此,为
-size
和-geometry
开关指定相同的尺寸。例如:convert-size 352x288-composite sydney.png jet2.png-geometry 352x288+0+0-depth 8 test.png
将拉伸飞机以适应图像窗口。这可能会起作用,但我事先不知道图像的大小,所以如果它可以自动拉伸或其他任何东西,那就好了。您可以使用下面的bash命令:size=
identify-format“%wx%h”filename.png`然后将其转换为bash脚本。不幸的是,Imagemagick似乎没有一个-autostretchortwhich
开关。好的,这就是我刚刚做的-工作非常漂亮,非常感谢!不客气。不管怎样,我还是写了一个脚本给你——看看我更新的答案。