2011-10-21 12 views
0

imagemagickのコマンドラインを統合し、収差を修正して画像の背景にあるグラフである目的の効果を得る方法を探しています。imageMagickコマンドの統合?

イメージファイルhereが表示されます。ここに埋め込むと、スタックオーバーフローのレイアウトが混乱することになります。

最初のイメージはソースグラフです。 2番目と3番目の画像は、次の理由で失敗とみなされます。

2背景とグラフのサイズを に正しく設定しようとすると、背景が途切れます。私はあなたがテキストのバックグラウンド

第四の画像がありません見ることができます黒の背景を追加しませんでした は、私が例で使用した背景です。

私が目指しているのは、背景がフィットするようにスケーリングされているが、伸びたり縮んだりしていないグラフです。背景ファイルは常にグラフよりも大きな次元になります。

以下は、私が何をやっているのかを説明するためにいくつかのノートで例を得るためにノックアップしたスクリプトです。

基本的には、グラフサイズを塗りつぶすまで背景画像を拡大/縮小して余白を切り抜くことです。

誰でも手伝ってください。


#!/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 

答えて

1

私が正しいとすれば、最小の寸法で元の画像に背景を塗りつぶして、拡大領域をカットしたいとします。そのためのおかげで - 私は完全に '^' を逃したと思います

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

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

+0

:あなたは^オプションと-extent-resizeを使用することによって、これを達成することができます。 – Fuzzy

関連する問題