Write to an image (text centered, kerning,etc)

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
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Write to an image (text centered, kerning,etc)

Post by myspacee »

Hello,
for job i need to write some lines on an white image. But i've some limit and rules to follow.

I want to obtain this:
Image

start from this script:
(last IM version, Windows XP)

Code: Select all

convert starting_white_template.tif -font AmplitudeComp-Regular -weight 700  -pointsize 200 -draw "gravity north fill black text 0,300 'OIL' " corpo.tif
convert corpo.tif -font AmplitudeComp-Regular -weight 700  -pointsize 200 -draw "gravity north fill black text 0,500 'FOUND' " corpo.tif
convert corpo.tif -font AmplitudeComp-Regular -weight 700  -pointsize 200 -draw "gravity north fill black text 0,700 'IN CENTRAL PARKING BLA BLA' " corpo.tif
but I need help :
- center text in my start template
- fit all text horizontally when is too long (eg: 'IN CENTRAL PARKING BLA BLA')
- better syntax as see in doc for switch 'label:' and pass my text in this way :

Code: Select all

label:'First\nSecond\nThird'
Read about Kerning, but I need help to apply this 'effect' to all my text, and not only for long one.

Thank you for your attention and help,
m.
Last edited by myspacee on 2013-10-02T01:35:36-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Write to an image (text centered, kerning,etc)

Post by snibgo »

You could use one command, eg:

Code: Select all

convert -size 2400x1200 xc:White ^
  -gravity Center ^
  -weight 700 -pointsize 200 ^
  -annotate 0 "OIL\nFOUND\nIN CENTRAL PARK" ^
  oil.png
See also http://www.imagemagick.org/Usage/text/
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: Write to an image (text centered, kerning,etc)

Post by fmw42 »

You can also try using caption: and optionally specify only the width.


convert -background white \
-gravity Center \
-weight 700 -pointsize 200 \
caption:"OIL FOUND IN CENTRAL PARK BLA BLA BLA" \
oil.png


convert -background white -size 1500x \
-gravity Center \
-weight 700 -pointsize 200 \
caption:"OIL FOUND IN CENTRAL PARK BLA BLA BLA" \
oil2.png


convert -background white -size 1500x \
-gravity Center \
-weight 700 -pointsize 200 -kerning 10 \
caption:"OIL FOUND IN CENTRAL PARK BLA BLA BLA" \
oil3.png
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Write to an image (text centered, kerning,etc)

Post by myspacee »

Thank you both for reply.

Re-starting from snibgo syntax, but i must change strategy.
(must respect given text, can't reassemble words)

I need to create final image with fix Width and Height; this image it's a piece of my final product.
Must have W & H fix to assemble with other, given, pieces.

-- first step
I think to create a starting image with H=1000 and W=5000. This allow any phrase to fit in Width.
Then trim horizontally. From online doc i found way to trim :

Code: Select all

convert oil4.png -trim +repage trim_oneside.gif
but command trim also Height that i want to preserve, how trim white only horizontally ?

-- second step
I obtained a rectangle from first step, how use composite to center this image in another bigger one ?

thank you again for any help,
m.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Write to an image (text centered, kerning,etc)

Post by snibgo »

myspacee wrote:but command trim also Height that i want to preserve, how trim white only horizontally?
See http://www.imagemagick.org/Usage/crop/#trim_oneside
myspacee wrote:I obtained a rectangle from first step, how use composite to center this image in another bigger one?
Possibly with "-gravity center" and "-compose Over -composite". See http://www.imagemagick.org/Usage/compose/
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: Write to an image (text centered, kerning,etc)

Post by fmw42 »

You cannot specify width and height AND pointsize and expect it to fit all the time. If you pointsize is too big, it will exceed the boundaries of the width and height.

You can specify width and height and leave off the pointsize and use caption: to make it best fit that size. The pointsize will be determined to make it fit.



convert -background white -size 2400x1200 \
-gravity Center \
-weight 700 \
caption:"OIL FOUND IN CENTRAL PARK BLA BLA BLA" \
oil4.png
Post Reply