Fixed width image with label help

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
robocop
Posts: 32
Joined: 2013-03-22T23:15:09-07:00
Authentication code: 6789

Fixed width image with label help

Post 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!
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 | Ubuntu 18.04.1 LTS
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fixed width image with label help

Post 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
robocop
Posts: 32
Joined: 2013-03-22T23:15:09-07:00
Authentication code: 6789

Re: Fixed width image with label help

Post 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
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 | Ubuntu 18.04.1 LTS
Post Reply