Page 1 of 1

Fixed width image with label help

Posted: 2014-04-09T04:40:19-07:00
by robocop
Hi :)

I'm having a small issue and hope someone can please help. I've checkedhttp://www.imagemagick.org/Usage/text/ and haven't had much luck.

I'm using this command below to generate an image label.

Code: Select all

convert -size 300x187 -gravity center label:"Quick Test" test.png
which generates:
Image

I found the code at viewtopic.php?f=3&t=22964#p98250

I would like to place a background image behind the text label ( fixed width ) and let the font text to auto scale in size without adding the -pointsize parameter.

The background image would be exactly the same size 300x187

Image

Basically so it would be something like this:
Image


I hope it's nothing too big and someone could help me.

Thanks very much!

Re: Fixed width image with label help

Posted: 2014-04-09T09:53:57-07:00
by fmw42
You have to create the test to the size of the background image and overlay it. But if you want padding on the sides as in the last example, then you must specify the size reduced by the padding.

You do not mention your IM version or platform, which you should always do, since syntax differs between unix and windows.

Here is unix syntax.


buffer=20
ww=`convert pJxd9YV.jpg -format "%[fx:(w-2*$buffer)]" info:`
convert pJxd9YV.jpg \
\( -size ${ww}x -background none -fill white -font arial label:"Quick Test" \) \
-gravity center -compose over -composite result.jpg

Re: Fixed width image with label help

Posted: 2014-04-09T18:28:44-07:00
by robocop
fmw42 wrote:You have to create the test to the size of the background image and overlay it. But if you want padding on the sides as in the last example, then you must specify the size reduced by the padding.

You do not mention your IM version or platform, which you should always do, since syntax differs between unix and windows.

Here is unix syntax.


buffer=20
ww=`convert pJxd9YV.jpg -format "%[fx:(w-2*$buffer)]" info:`
convert pJxd9YV.jpg \
\( -size ${ww}x -background none -fill white -font arial label:"Quick Test" \) \
-gravity center -compose over -composite result.jpg


Hi Fred :)

Sorry i didn't mention it earlier, I'm on a Ubuntu with Version: ImageMagick 6.5.7-8 2012-08-17 Q16

Thank you very much for the syntax you gave, it's worked perfectly just the way I was hoping for! I'll adjust the padding accordingly for my work.

Cheers for explaining everything!
I appreciate your help and Thank you again Fred :D