Page 1 of 1

creating textbox on top of image

Posted: 2008-05-22T09:24:15-07:00
by YOzefff
Hi,

I have a image and a want to add some text on a specific X,Y location and bounded by a with and height.

I have read

http://www.imagemagick.org/Usage/annotating/#annotating

but can't get it to work ...

HELP?

Re: creating textbox on top of image

Posted: 2008-05-22T09:27:58-07:00
by Bonzo
How about posting a copy of what you have tried.

Some examples on my site:
http://www.rubblewebs.co.uk/imagemagick/text.php
http://www.rubblewebs.co.uk/imagemagick/watermark.php

Re: creating textbox on top of image

Posted: 2008-05-23T01:38:27-07:00
by YOzefff
well first start was

Code: Select all

$text="Verrrrrrryyyy loong an a lot of text what needs to be boundend by a with and height";

					$command = $image_magick.' -resize 2480x3508 "'.$source_image.'" '.
					' -font "'. $fonts["title"] .'" -pointsize 120 -fill white '.
					' -draw "text 308, 530 \''.$text.'\'"  "'.$target_image.'"';					
					passthru($command);	
but now my text just runs of the image

Re: creating textbox on top of image

Posted: 2008-06-03T20:13:09-07:00
by anthony
In stead of specifying a specific point size, let label: or caption:
automatically determine the best size for the text to fit into the area wanted.

See the "Auto-Sized Caption" example in Annotate

Re: creating textbox on top of image

Posted: 2008-06-04T00:32:37-07:00
by YOzefff
hmm interresting .. I will try that ...

For now I've used this solution:

created a dummy transparent image with the width and height of the textbox and put de text in it. Then I merged the master image with the dummy image.

thnx

Re: creating textbox on top of image

Posted: 2009-09-14T14:45:18-07:00
by anakadote
or now I've used this solution:

created a dummy transparent image with the width and height of the textbox and put de text in it. Then I merged the master image with the dummy image.
Can you please provide some example code of how you did this?

Re: creating textbox on top of image

Posted: 2009-09-15T00:02:20-07:00
by Bonzo
Untested code but something like this should work:

Code: Select all

convert -size 200x100 xc:none caption: 'Some text here' text.png
composite -gravity center text.png image.jpg output.jpg
Al on one line may work

Code: Select all

convert -size 200x100 xc:none caption: 'Some text here' miff:- | composite -gravity center - image.jpg output.jpg
This code can be expanded to specify a font coloured backgound or border to the text box etc.

Re: creating textbox on top of image

Posted: 2009-09-15T18:16:34-07:00
by anthony
Or even one command!

Code: Select all

convert -size 200x100 xc:none caption: 'Some text here' \
            image.jpg +swap -gravity center - composite output.jpg