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
source to share
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):
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
source to share