PANGO center vertically

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
soyxan
Posts: 9
Joined: 2017-04-29T07:47:20-07:00
Authentication code: 1151

PANGO center vertically

Post by soyxan » 2017-10-30T03:47:58-07:00

By default pango: command can be centered horizontally with "-gravity Center".

How can I center vertically given a canvas size?

I am trying to do it this way with no success (my canvas size is 320x96):

Code: Select all

convert -size 320x96 -background black ( -gravity Center -background red -font %1 -pointsize %2 pango:%3 ) -gravity center -composite output.jpg
%1,%2,%3 are placeholders for BATCH variables.

snibgo
Posts: 9379
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: PANGO center vertically

Post by snibgo » 2017-10-30T05:22:00-07:00

"-composite" needs two input images. You have only one, created by "pango:". Perhaps you intended something like "xc:white" after setting the background.
snibgo's IM pages: im.snibgo.com

soyxan
Posts: 9
Joined: 2017-04-29T07:47:20-07:00
Authentication code: 1151

Re: PANGO center vertically

Post by soyxan » 2017-10-30T09:54:38-07:00

With the following command I get the text in the upper position (not centered vertically)

Code: Select all

convert -size 320x96 -background black xc:white ( -gravity Center -background red -font "Verdana" -pointsize 32 pango:test ) -gravity center -composite output.jpg

snibgo
Posts: 9379
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: PANGO center vertically

Post by snibgo » 2017-10-30T10:24:51-07:00

"+write x.png" (with any filename) is a useful debugging tool. If you put this before the close parentheses, you will see the problem, that the "pango:" image is larger than you want, because it is using your initial "-size".

There are many possible fixes. One is to use "+size" after the open parenthesis, so "pango:" isn't given a size, so its result is small.
snibgo's IM pages: im.snibgo.com

User avatar
GeeMack
Posts: 469
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: PANGO center vertically

Post by GeeMack » 2017-10-30T10:25:06-07:00

soyxan wrote:
2017-10-30T09:54:38-07:00
With the following command I get the text in the upper position (not centered vertically)

Code: Select all

convert -size 320x96 -background black xc:white ( -gravity Center -background red -font "Verdana" -pointsize 32 pango:test ) -gravity center -composite output.jpg
Pango is using your "-size 320x96" as the size for its own container with the text centered horizontally, but starting at the top. You can get the text centered vertically by removing the canvas size setting after creating your canvas by using "+size" in a command like this...

Code: Select all

convert -size 320x96 -background black xc:red +size -gravity Center ^
   ( -background red -font "Verdana" -pointsize 32 pango:test ) -composite output.jpg
That way Pango only makes the container large enough for the text you provide, and the vertical centering is done during the composite operation according to the gravity setting.

Post Reply