Fontsize + viewport + trim

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
gregory
Posts: 67
Joined: 2009-08-02T17:20:23-07:00
Authentication code: 8675309

Fontsize + viewport + trim

Post by gregory »

Hey guys,

I have a problem. I'm trying to create a picture using a user's text and font size. Unfortunately, I don't know the font size, font type and text length before creating a picture.
So I have to predefine somehow "-size" and "option:distort:viewport" options. But how? How to determine the width and height of the image I will need for this picture?
For example, I have text "I love you", font "Aactionman" and font size 50. What's next? I don't want to create a very big image since "-trim" option for some reason doesn't trim animations. If I would know the width and height of each letter in a font I would calculate image dimensions, but I don't know...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fontsize + viewport + trim

Post by fmw42 »

If you have the text, font and pointsize, then just do the following, (I don't have Aactionman font so you can use yours -- I just used Arial)

convert -background white -fill black -font Arial -pointsize 50 label:"I love you" -trim +repage result.gif
gregory
Posts: 67
Joined: 2009-08-02T17:20:23-07:00
Authentication code: 8675309

Re: Fontsize + viewport + trim

Post by gregory »

I use the following code:

Code: Select all

code
(where animation.gif -- any gif animation)

As you can see the STROKE is blinking. If I delete "+repage" option everything is okay but image is not trimmed.

Could you please help me to create trimmed animation without using "-size" and "viewport" options?
Last edited by gregory on 2012-04-12T16:46:05-07:00, edited 1 time in total.
gregory
Posts: 67
Joined: 2009-08-02T17:20:23-07:00
Authentication code: 8675309

Re: Fontsize + viewport + trim

Post by gregory »

I would also appreciate if you help me to optimize this query. I assume third step can be combined with the first one but I don't know how to do it. I tried many variations with no success.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Fontsize + viewport + trim

Post by anthony »

More information about the text geometry used during the annotation of text can be gathered.

See IM Examples, Text to Image Handling, Determining Font Metrics
http://www.imagemagick.org/Usage/text/#font_info
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
gregory
Posts: 67
Joined: 2009-08-02T17:20:23-07:00
Authentication code: 8675309

Re: Fontsize + viewport + trim

Post by gregory »

Okay, but how to solve the bug I mentioned above? I mean stroke blinking.
gregory
Posts: 67
Joined: 2009-08-02T17:20:23-07:00
Authentication code: 8675309

Re: Fontsize + viewport + trim

Post by gregory »

I solved the issue by using "-draw" instead of "label".
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Fontsize + viewport + trim

Post by anthony »

label: creates an image. Blinking means you created a GIF animation.

Instead of -draw, you can use -annotate.

For more examples see
Automatically Sized Annotated Text Canvases
http://www.imagemagick.org/Usage/text/#annotate_size

This goes on to adding color and even gradients to the text image.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply