ImageMagick - text to rectangle

I am very new to ImageMagick - I read some documentation and now I am in the first real situation. I have an image (300 * 500), and I have text that should be as good as possible (maximum possible) at 20% of the top of the image. So the text should be in the rectangle 300 * 100, the rest of the image will remain the same. Is this possible with image magic? What is the best way to do this

I am looking for a command line solution or php extension. Simple illustration below.

Simple ilustration

+5
source share
1 answer

Since you did not provide a sample image for testing and applying some text, I created it with the following command:

convert                               \
   http://i.stack.imgur.com/RfJG6.png \
  -crop 312x513+579+0 +repage         \
   so#12231624-right.png

, , , ( Linux Mac OS X):

width=$(identify -format %W so#12231624-right.png)

convert                  \
  -background '#0008'    \
  -gravity center        \
  -fill white            \
  -size ${width}x100     \
   caption:"This is a sample text to test \
the automatic sizing of fonts by ImageMagick." \
   so#12231624-right.png \
 +swap                   \
 -gravity north          \
 -composite              \
  output1.png

convert                  \
  -background '#0008'    \
  -gravity center        \
  -fill white            \
  -size ${width}x100     \
   caption:"This is a even longer sample text. \
It also serves to test if automatic sizing of fonts \
by ImageMagick works as expected: just don't specify \
any fontsize, and let ImageMagick go for the best fit..." \
   so#12231624-right.png \
 +swap                   \
 -gravity north          \
 -composite              \
  output2.png

:

output example 1output example 2

( - , , ( ), ...)

: -fontsize. , . ImageMagick .

+7

All Articles