multiple line autofit text overlay problem

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
magatyb
Posts: 6
Joined: 2015-07-01T04:57:02-07:00
Authentication code: 6789

multiple line autofit text overlay problem

Post by magatyb »

Hi . I need to add a two line overlay to an existing picture b.jpg, having width of 1024px with c.jpg as output:

convert B.jpg ( -background none -size 1024x -fill white -font Calibri label:"this is line1\n this is line2" ) -gravity Center -compose over -composite C.jpg

and line2 isn't showing.

What am I doing wrong?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: multiple line autofit text overlay problem

Post by snibgo »

For multi-line "label:", you need to specify both width and height. You could trim the result.
snibgo's IM pages: im.snibgo.com
magatyb
Posts: 6
Joined: 2015-07-01T04:57:02-07:00
Authentication code: 6789

Re: multiple line autofit text overlay problem

Post by magatyb »

Thank you for your answer.
I've tried your suggestion and now the text isn't centered anymore, but instead it's aligned top left.
This is the command used:

convert B.jpg ( -background none -size 1024x768 -fill white -font Calibri label:"this is line1\n this is line2" ) -gravity Center -compose over -composite C.jpg
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: multiple line autofit text overlay problem

Post by snibgo »

Put "-gravity Center" before "label:".
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: multiple line autofit text overlay problem

Post by fmw42 »

I am not sure what you mean by not centered any more. If you mean that the text image is not centered in the background because of uneven transparent borderinig, then try adding -trim +repage as

Code: Select all

convert B.jpg ( -background none -size 1024x768 -fill white -font Calibri -gravity center label:"this is line1\n this is line2" -trim +repage ) -gravity Center -compose over -composite C.jpg
If you mean that the two lines of text are not center justified, then add -gravity center before label: as above. Or use caption: rather than label: and do not put in new lines using "\n". Adjust the width so that the autowrap breaks the text into two lines as desired.


You could also just write the text directly into image B.jpg using -annotate.

See
http://www.imagemagick.org/Usage/text/
magatyb
Posts: 6
Joined: 2015-07-01T04:57:02-07:00
Authentication code: 6789

Re: multiple line autofit text overlay problem

Post by magatyb »

Thank you for your answers. That solved the problem.
Now I want to make the text to look a bit 'italic' and did this:

convert B.jpg ( -background none -size 1024x768 -fill white -font Calibri -gravity center -annotate 0x20+50+50 label:"this is line1\n this is line2" -trim +repage ) -gravity Center -compose over -composite C.jpg

and got this error:

convert.exe: no images defined `C.jpg' @ error/convert.c/ConvertImageCommand/3212.

Is it possible to accomplish this using -annotate? or should I just use a font that looks italic?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: multiple line autofit text overlay problem

Post by fmw42 »

Your syntax is wrong. Either use -annotate or label: but not both

Pick a pointsize and use

Code: Select all

convert B.jpg -fill white -font Calibri -pointsize X -gravity center -annotate 0x20+0+0  "this is line1\n this is line2" C.jpg
Adjust the +0+0 offsets as desired.

If you need the two lines of text justified, then you probably want to use label: as before, but with an italics font. Or install Pango and use pango: and select italic styling. Or do annotate twice, once for each line. See example at http://www.imagemagick.org/Usage/text/#annotate

See http://www.imagemagick.org/Usage/text/#pango
magatyb
Posts: 6
Joined: 2015-07-01T04:57:02-07:00
Authentication code: 6789

Re: multiple line autofit text overlay problem

Post by magatyb »

Using -pointsize won't allow autofit, Pango is also a bit too much, so I guess I'll go look up a more appropriate font.
Thank you all for your help.
Post Reply