ImageMagick: text How to auto-validate text in a transparent window

  • I have a photo called funny-santa.jpg (Google Image it, that's cute).
  • I was able to draw a yellow ONTO box funny-santa.jpg '
  • I can put TEXT in this yellow frame. ("Merry Christmas Mom and Dad").
  • How do I automatically insert text into the yellow box I created - programmatically?
  • Is it possible to auto-fit the text below to a given space?

Here is the code to draw a "TRANSPARENT" rectangle on an existing image. I added the document text "Merry Xmas Mom and Dad" in the document. The challenge is this: how can I automatically fit the "Cheerful Mom and Mom" ​​in the box I just created?

  • What if my text changes to "I love you mom and dad." Any "hardcoded values" based on the text dimension should be rewritten.

    convert funny-santa.jpg -strokewidth 0 -fill "rgba (255, 215, 0, 0.5)" -driver "rectangle 0.0 1024 350" -point 30-black black -independent + 67 + 60 'Merry Christmas mom and dad 'output.jpg

+3


source to share


2 answers


You can also see this answer from me from 15 months ago:

If you use the correct method, the text will automatically match. Let's use a box that is 270px wide and 70px high. Here is the command I used, first with 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 above, image with text below):



QsMnV.jpg1433l.jpg

If you want to put longer text in the same field, just use the longer text :-)

Look at 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 

      

64fgD.jpg

+5


source


convert -size 1024x300 -background rgba (0,255,255,0.25) - scoop up the inscription of the black engraving: "Merry Mom" ​​cap.png



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

0


source







All Articles