Page 1 of 1
PANGO center vertically
Posted: 2017-10-30T03:47:58-07:00
by soyxan
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.
Re: PANGO center vertically
Posted: 2017-10-30T05:22:00-07:00
by snibgo
"-composite" needs two input images. You have only one, created by "pango:". Perhaps you intended something like "xc:white" after setting the background.
Re: PANGO center vertically
Posted: 2017-10-30T09:54:38-07:00
by soyxan
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
Re: PANGO center vertically
Posted: 2017-10-30T10:24:51-07:00
by snibgo
"+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.
Re: PANGO center vertically
Posted: 2017-10-30T10:25:06-07:00
by GeeMack
soyxan wrote: ↑2017-10-30T09:54:38-07:00With 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.