【问题标题】:imageMagick command consolidaton?imageMagick 命令整合?
【发布时间】:2011-12-12 16:45:02
【问题描述】:

我正在寻找一种方法来整合我的 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

【问题讨论】:

    标签: linux image-processing imagemagick


    【解决方案1】:

    如果我做对了,你想用最小的尺寸用背景填充原始图像并剪切扩展区域。您可以通过使用-resize^ 选项和-extent 来实现此目的:

    convert background.jpg -resize 100x100^ -extent 100x100 background_resize.jpg
    

    http://www.imagemagick.org/Usage/resize/#fill

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-27
      相关资源
      最近更新 更多