如何用imagemagic扩展一张图片的画布大小?

不是扩展图片的大小,而是扩展图片的画布

简单说就是在图片周围增加空白部分。

I know about extend and gravity. I have an image and I want to increase its canvas size to 400×400 AND I want to take the existing image and place it at a specific X and Y in the canvas. I have the Specific values, but I need the ability to move the image there.

Here is an Example.

 width = 52 
 page.x = 158
 400 - width - page.x = 190

 height = 107
 page.y = 146
 400 - height - page.y = 147

In this example the image needs to be resize from 52×107 to 400×400 and the image needs to start at 158×146 in this need 400×400 canvas.

方法

If your not distorting the original 52×107 image, then it might be as simple as -repage +{left}+{top}.

# Given a 52x107 image.
convert -size 52x107 xc:orange 52x107.png

# Create a blank canvas to act as the padding.
convert -size 400x400 xc:lime \( 52x107.png -repage +158+146 \) -flatten out.png

In this example the image needs to be resize from 52×107 to 400×400 and the image needs to start at 158×146 in this need 400×400 canvas.

However it sounds like you do want to resize the small image to 400×400, and adjust offset w/ padding.

# Using rose: for example
convert -size 400x400! xc:lime \
        \( rose: -resize 400x400! -repage +158+146 \) \
        -flatten out2.png

or … attempting something more dynamic

OFFSET=$(identify -format '+%[fx:(400-w)/2]+%[fx:(400-h)/2]' rose:)
convert rose: -repage $OFFEST \
        \( +clone -resize 400x400! -repage +0+0 \) \
        -swap 0,1 -flatten out3.png

But, perhaps, I’m not understanding the OP question.

本文文字及图片出自 出处

阅读余下内容
 

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注


京ICP备12002735号