Creating text layer with annotate (WxH)

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
immortal26

Creating text layer with annotate (WxH)

Post by immortal26 »

Here is my current code:

Code: Select all

$final = "convert -font ".$font." -pointsize 90 -kerning 10 -fill White -size 1000x1000 xc:black -gravity center -annotate ".$skewx."x".$skewy."+0+0 '".$text."'  final".$png;
exec($final, $result);
It's in php but it works fine, but...
I would like to be able to create the text without having to set the size because it increases rendering time by alot.
Let's just say I know what the width and height can be before the text layer is created.
But as you can see I'm using annotate with some skewing, so without the size I lose text.
Is there anyway I can create the text layer with annotate without defining the size of the canvas?

Thanks
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Creating text layer with annotate (WxH)

Post by Bonzo »

Try caption

Code: Select all

$final = "convert -font $font -pointsize 90 -kerning 10 -fill White xc:black -gravity center caption: \"$text\"  output.png";
exec($final, $result);
immortal26

Re: Creating text layer with annotate (WxH)

Post by immortal26 »

That works fine and all but i need the annotation for skewing XxY coords
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Creating text layer with annotate (WxH)

Post by fmw42 »

Is there anyway I can create the text layer with annotate without defining the size of the canvas?
Not that I know of. I have always had to use label: or caption: first to get the size, then use that size with -annotate.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Creating text layer with annotate (WxH)

Post by anthony »

You could create the label or caption then distort it!

-distort affine has some very good controls to fine tune the distortion. For affine distorts the 'output scaling' control with post distort resize work very well.

Of course you are then distorting a raster image, when -annotate (like -draw) actually distorts the vector control points keeping the text as sharp as it can possibility be.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Creating text layer with annotate (WxH)

Post by anthony »

The other way was outlined in
Automatically Sized Annotated Text Canvases
http://www.imagemagick.org/Usage/text/#annotate_size

This uses 'label to generate the canvas, (whcih can also then be size adjusted) but then uses
Annotate to do the drawing as, as you say, annotate has more features (like skew, and tiling) that label does not have.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Creating text layer with annotate (WxH)

Post by snibgo »

It's a shame that "-debug annotate" doesn't seem to take shear into account.

immortal26: I suspect your concern is in the time required for subsequent processing: writing then processing a text file of a million pixels.

If so, you might "-trim" the file, and take note of the canvas offsets. The processing is then of the bounding rectangle. When you have found the pixels of interest, add the offsets to the found coordinates.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Creating text layer with annotate (WxH)

Post by fmw42 »

I don't know if this helps, but you can do this so no image need be written to disk

size=`convert -size 100x -background lightblue label:"Something" -format "%wx%h" info:`
echo "$size"
100x25
Post Reply