Basic example of using magick++

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
lykmyk
Posts: 2
Joined: 2012-01-14T21:44:25-07:00
Authentication code: 8675308

Basic example of using magick++

Post by lykmyk »

Hello all: I am new to magick++ and just barely started reading the documentations. I would appreciate it if someone showed me some basics please.

Here is an example of an simple image i would like to create:

1. An image with a plain with background
2. On the Image place name and address text on the left
3. Place a cell on the right (with a black border) and in the cell put a phone number
4. Underneath the cell place city and state.

I would really appreciate any help.

Thanks.

-------------------------------------------------------
| My Name Here ------------------------- |
| Address here | phone number here | |
| ------------------------- |
| |
| City and State |
-------------------------------------------------------
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Basic example of using magick++

Post by fmw42 »

Here is one way (replace _____ with as many spaces as you want):

convert -background white \
-gravity west -fill black -font Arial -pointsize 24 \
label:"My Name Here\nAddress Here_____Phone Number Here\n\n\nCity and State" \
result.png

see
http://www.imagemagick.org/Usage/text/#label
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Basic example of using magick++

Post by anthony »

If the number of spaces to be left are in 'pixels' or 'real world units' then you will either need to DIY formatting
where you calculate and directly place each text label in specific places, to leave the space wanted. EG: number of spaces needed for 'this much' real world space, actually depends on the font you are using.
You will need to get 'font infomation' to do that calculation!

Or you could go with something that can format the text in that way.. For example 'Pango'.


The latest changes in ImageMagick that should allow the use of 'pango' formatted text in image generation, but I am not certain of the details. I do see in my lastest IMv6 compliation...

Code: Select all

convert -list format
  ...
  CAPTION* CAPTION   r--   Caption (Pangoft2 1.28.1)
  ...
So I would assume that 'caption' now allows for pango formatted text strings!
EG perhaps this would have worked (pango does not require a 'size' where old caption: did)

Code: Select all

convert caption:'<b>bold</b> <i>italic</i> <u>underlined</u>' show:
Nope I get a BLANK image -- looks like a bug -- reporting...

ASIDE: I would have preferred a separate "pango:" text image format instead, and left "caption:" as is for backward compatibility!


Linking back to the original question... The above can be directly used in any API, by just 'reading image' using the formatted image generator. EG: something like (as a guess) image=image_info->ReadImage("caption:.....");
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Basic example of using magick++

Post by magick »

ImageMagick supports these Pango options: caption:hinting, caption:language, caption:gravity-hint, caption:auto-dir, caption:ellipsize, caption:justify, caption:single-paragraph,caption:wrap, caption:indent, and caption:markup. Try -define caption:markup=true. Note you must use the Pango markup language, for example:
  • convert -define caption:markup=true caption:'<b>ImageMagick</b> is <i>cool</i>!' show:
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Basic example of using magick++

Post by anthony »

thanks for the explanation of how to enable pango markup in caption.

But why then did my caption test (even with all the mark up) produce a blank image?
I should have at least gotten an image with the text (including the markup tags).

In fact when I try your example I again produced a pure white only image!

Adding a -background grey only produced a pure grey image, and setting -fill makes no change at all!

This is on a Fedora 14 system, which I have not upgraded to F16 as yet.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply