Page 1 of 1

Creating text layer with annotate (WxH)

Posted: 2010-06-03T06:04:14-07:00
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

Re: Creating text layer with annotate (WxH)

Posted: 2010-06-03T07:31:43-07:00
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);

Re: Creating text layer with annotate (WxH)

Posted: 2010-06-03T07:51:15-07:00
by immortal26
That works fine and all but i need the annotation for skewing XxY coords

Re: Creating text layer with annotate (WxH)

Posted: 2010-06-03T09:11:42-07:00
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.

Re: Creating text layer with annotate (WxH)

Posted: 2010-06-03T22:56:09-07:00
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.

Re: Creating text layer with annotate (WxH)

Posted: 2010-06-03T22:58:38-07:00
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.

Re: Creating text layer with annotate (WxH)

Posted: 2010-06-04T11:43:20-07:00
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.

Re: Creating text layer with annotate (WxH)

Posted: 2010-06-04T14:08:06-07:00
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