Imagemagick: How to center a picture on a transparent canvas

时间:2015-07-28 16:53:40

标签: fonts imagemagick image-manipulation image-conversion

I am using ImageMagick to export glyphs from a font. However, some of these glyphs are smaller than others, and end up not being in the center of the image as a result of that. I am looking for a way to take a created image and center it on a transparent canvas. I am guessing this means that first the image should be cropped to remove all transparent regions around it, but I am not sure about that.

The ImageMagick command I'm using right now is:

convert -size 32x32 canvas:none -channel RGBA -font Fontname -pointsize 32 -fill white -gravity center -draw text 0,0 'a' ./image_cache/a.png

1 个答案:

答案 0 :(得分:0)

使用-trim从字形中删除额外的填充,并使用-extent将图像恢复为原始大小。

convert -size 32x32 -background pink \
        -font Fontname -pointsize 32 -fill white \
        label:a -trim -gravity center -extent 32x32 \
        ./image_cache/a.png

How to center a picture on a transparent canvas