3
  1. I have a picture called funny-santa.jpg (Google Image it, it is cute)
  2. I have been able to draw a yellow box ONTO funny-santa.jpg'
  3. I am able to put TEXT into that yellow box.("Merry Christmas Mom and Dad")
  4. How do I auto fit text within yellow box i created - Programatically?
  5. Is it possible to auto-fit the below text to a pre-defined space?

Here is the code to draw a TRANSPARENT Yellow box onto an existing picture. I have added the text 'Merry Xmas Mom and Dad" within the document. The challenge is this: How do I auto-fit my 'Merry Xmas Mom and Dad' within the Box I just created?

  1. What if my text were to change to "I love You Mom and Dad". Any 'hard-coded values' based on text dimension would have to be redone.

    convert funny-santa.jpg -strokewidth 0 -fill "rgba( 255, 215, 0 , 0.5 )" -draw "rectangle 0,0 1024,350" -pointsize 30 -fill black -annotate +67+60 'Merry Christmas Mom and Dad' output.jpg

user229044
  • 232,980
  • 40
  • 330
  • 338
FlyingV
  • 2,207
  • 19
  • 18

2 Answers2

7

You could also look at this answer of me from 15 months ago:

If you use the correct method, the text will fit automatically. Let's use a box with 270 pixels width and 70 pixels height. Here is the command I used, at first with a short text:

mytext="Cheers\!"

convert                            \
  -background '#0008'              \
  -gravity center                  \
  -fill white                      \
  -size 260x70 caption:"${mytext}" \
   funny-santa.jpg                 \
  +swap                            \
  -gravity south                   \
  -composite                       \
   funny-santa---1.jpg 

Here is the result (original image on top, image with text on bottom):

If you want to put longer text into the same box, just use longer text :-)

Look here:

mytext="Dear Kids\! One day you'll learn everything about Santa Claus. On that day, please also remember what they told you about Jesus."

convert                            \
  -background '#0008'              \
  -gravity center                  \
  -fill white                      \
  -size 260x70 caption:"${mytext}" \
   funny-santa.jpg                 \
  +swap                            \
  -gravity south                   \
  -composite                       \
   funny-santa---2.jpg 

Community
  • 1
  • 1
Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
0

convert -size 1024x300 -background rgba(0,255,255,0.25) -fill black -gravity center caption:'Merry Xmas Mom' cap.png

composite -geometry +0+0 cap.png funny-santa.jpg funny-santa-vic.jpg

FlyingV
  • 2,207
  • 19
  • 18