我正在寻找一种方法来合并我的imagemagick命令行,并修复像差,以获得所需的效果,即图像背景上的图形。
你可以看到图片文件here -我认为在这里嵌入它们会使堆栈溢出中的布局变得一团糟。
你可以看到的第一张图片是源图。第二个和第三个图像是我认为失败的,因为在以下情况下:
2由于试图使背景和图形大小正确匹配,背景被截断。
3在我没有添加黑色背景的地方,你可以看到文本没有背景
第四张图片是我在示例中使用的背景。
我的目标是一个背景缩放以适应的图表,而不是拉伸或挤压以适应。背景文件的尺寸始终大于图形的尺寸。
下面是我拼凑出来的脚本,其中包含一些注释,用来解释要做什么。
基本上我所追求的是缩放背景图像,直到它填满图形大小,裁剪任何多余的。
有人能帮上忙吗?
#!/bin/bash
if [ -z "$3" ]
then
echo "usage: $0 background.png foreground.png output.png"
exit 1
fi
orig_size=`identify -format '%wx%h' "$2"`
bg_size=`identify -format '%wx%h' "$1"`
# make a black background size of graph
convert -size $orig_size xc:black ./thisblack.png
# resize background image to size of graph
# this might result in areas with no background
convert -resize $orig_size "$1" "_$1"
# make the graph the background to force size
# by merging the graph and resized background.
# By using the graph as first parameter the size
# is always correct (even though you can't see
# the graph in this image)
convert -composite "$2" "_$1" -depth 8 "_$3"
# overlay graph onto the composite background and graph
# so we can see the graph again
convert -size $orig_size -composite "_$3" "$2" -depth 8 "__$3"
# merge the black and final graph for end image and fill
# areas with no background with black.
convert -composite "thisblack.png" "__$3" -depth 8 "$3"
# Clean up
rm -f "__$3"
rm -f "_$3"
rm -f "_$1"
rm -f thisblack.png发布于 2011-10-24 14:49:00
如果我没弄错的话,你想用最小的尺寸填充一个原始图像的背景,然后剪切扩展区域。您可以通过将-resize与^选项和-extent配合使用来实现此目的
convert background.jpg -resize 100x100^ -extent 100x100 background_resize.jpghttp://www.imagemagick.org/Usage/resize/#fill
https://stackoverflow.com/questions/7851744
复制相似问题