Page 1 of 1
Size image to fit text
Posted: 2015-10-28T06:34:39-07:00
by TheReaper
Hi,
I want to place some text on a existing image, but I want the image fit the text (not the other way around).
Let's say I have circle image and want to put some arbitrary text on it. I would like to resize/scale the circle image to the same size of the text.
Example without the resizing the image:
Code: Select all
convert CircleBanner.png -fill white -font TimesNewRoman -pointsize 50 \
-gravity center -annotate 0 "This text doesn't really fit" circleWithText.png
Preferable I would like to be able to do it with only one command execution (no pipelining or separate command executions) if possible.
Regards
M
Re: Size image to fit text
Posted: 2015-10-28T07:03:06-07:00
by snibgo
I don't understand the problem.
When you have created an image that happens to be from text, you want to resize another image to the same dimensions, so the text will fit. Is that correct?
Resizing to dimensions calculated within one command is messy, but can be done with distort and a viewport.
Re: Size image to fit text
Posted: 2015-10-28T07:18:56-07:00
by TheReaper
you want to resize another image to the same dimensions, so the text will fit. Is that correct?
Yes! Instead of making the text to automatically fit the image (as you can fulfil by omitting the pointsize for a label), I want a static size of the text and the Image to fit the text instead.
Re: Size image to fit text
Posted: 2015-10-28T09:55:42-07:00
by fmw42
If I understand what you want, you can create the text image with a transparent background using label: or caption:. Then you will need to resize your image to the size of the text image and composite them together. In order to know how to resize, you will have to get the text image size after creating it in a separate command. See string formats "%w" and "%h" at
http://www.imagemagick.org/script/escape.php. I do not think this can be done in one single command line in IM 6.
Re: Size image to fit text
Posted: 2015-10-28T15:37:16-07:00
by fmw42
Actually there is a way, if you know the size of the circle image ahead of time (since you have already created it). Assume my circle image is 256x256, then try (unix syntax)
Code: Select all
convert \
\( -background none -font arial -pointsize 64 label:"This is a Test" -set option:ratio "%[fx:w/256]" \) \
\( circle.png +distort SRT "%[ratio],0" \) +swap -gravity center -compose over -composite result.png
See
http://www.imagemagick.org/Usage/distorts/#srt
http://www.imagemagick.org/Usage/basics/#define
http://www.imagemagick.org/Usage/distor ... ol_escapes
Re: Size image to fit text
Posted: 2015-10-29T02:56:20-07:00
by TheReaper
Thank you
fmw42 ! I have played around with both solutions and they may work for my scenarios!
1. Created a script that identifies the size of the text,resizes the image and then adds the text to the image
2. Your example with the circle works, but now I need to learn more about the commands and arguments you are using so I understand how it works so I can tweak it