creating textbox on top of image

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
YOzefff

creating textbox on top of image

Post 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?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: creating textbox on top of image

Post 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
YOzefff

Re: creating textbox on top of image

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: creating textbox on top of image

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
YOzefff

Re: creating textbox on top of image

Post 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
anakadote

Re: creating textbox on top of image

Post 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?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: creating textbox on top of image

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: creating textbox on top of image

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply