Page 1 of 1

Label interword-spacing fit, but multiple spaces in text

Posted: 2016-05-11T00:39:36-07:00
by queensoft
I need to fit (justify) a text to the bottom of an image.
I use label interword-spacing fit, and it's great when there's just one single space in the text: "www.google.com (555)123-4567"
But, now I have multiple spaces: "www.google.com CALL (555) 123-4567"
I need the final text to be stretched like this:
-www.google.com-on the left side
- big empty gap in the middle
- CALL (555) 123-4567 - on the right side, one single space between words
Like this: http://www.google.com __________________ CALL (555) 123-4567
_ is space
My command line is this, the text is spread over the entire bottom evenly:

Code: Select all

www.google.com _____ CALL _____ (555) _____ 123-4567

Code: Select all

convert.exe -size 824x450 xc:none -font Arial -size 824x -fill #0d0707 -stroke rgb(255,255,255) -background transparent -gravity South -interword-spacing 100  label:"www.google.com CALL (555) 123-4567" -bordercolor transparent -border 15x15 -composite +repage -depth 8 output.png
Thanks.

Later edit: looks like I found a workaround:
1. save command output to a text line. Use underscores instead of spaces, so there's one single space in the text line.

Code: Select all

convert.exe -size 824x450 xc:none -font Arial -size 824x -fill #0d0707 -stroke rgb(255,255,255) -background transparent -gravity South -interword-spacing 100 -debug annotate  label:"www.google.com CALL_(555)_123-4567" -bordercolor transparent -border 15x15 -composite +repage -depth 8  null: 2> x.txt
Last line will contain the pointsize of the resulting text:

Code: Select all

 Font c:\windows\fonts\arial.ttf; font-encoding none; text-encoding none; pointsize 32.25
2. Extract pointsize using AutoIt, I'm pretty sure you can extract this using any simple tool/programming language.
3. Create 2 labels, SouthWest and SouthEast, use spaces this time:

Code: Select all

[code]convert.exe -size 824x450 xc:none -font Arial -fill #0d0707 -stroke rgb(255,255,255) -background transparent -gravity SouthWest -pointsize 32.25 label:"www.google.com" -compose over -composite -font Arial -fill #0d0707 -stroke rgb(255,255,255) -background transparent -gravity SouthEast -pointsize 32.25 label:"CALL (555) 123-4567" -bordercolor transparent -border 15x15 -composite +repage -depth 8  output.png
[/code]

Re: Label interword-spacing fit, but multiple spaces in text

Posted: 2016-05-11T03:33:12-07:00
by GeeMack
queensoft wrote:I need to fit (justify) a text to the bottom of an image.
It seems like "-annotate" might be a better tool to get what you want done. This seems to be pretty close...

Code: Select all

convert.exe -size 824x450 xc:none -font Arial -pointsize 32.25 -fill #0d0707 -stroke rgb(255,255,255) -background transparent -gravity southwest -annotate +0+0 "www.google.com" -gravity southeast -annotate +0+0 "CALL (555) 123-4567" -bordercolor transparent -border 15x15 +repage -depth 8 output.png
That places the text directly on your background canvas without any compositing.

Also, please provide the version of IM you're using and which OS you're working on.

Re: Label interword-spacing fit, but multiple spaces in text

Posted: 2016-05-11T03:54:18-07:00
by queensoft
Where did you get that pointsize value of 32.25 ?
I forgot to mention: I batch process many images.
Every time there's a different random font, I have about 800 fonts.
So, each font will have a different final pointsize.

I just put my workaround together and it seems to work perfectly.

I use Windows 7 Ultimate x64 SP1 and ImageMagick-7.0.1-Q16, 64 bits

Re: Label interword-spacing fit, but multiple spaces in text

Posted: 2016-05-11T04:58:27-07:00
by GeeMack
queensoft wrote:Where did you get that pointsize value of 32.25 ?
You found the pointsize. I didn't.
I forgot to mention: I batch process many images.
Every time there's a different random font, I have about 800 fonts.
So, each font will have a different final pointsize.
The "-interword-spacing" operator is based on number of pixels, not point size. Also, the width of an underscore will not necessarily be the same as the width of a space, so your spacing is somewhat arbitrary any way you're doing it. If you just want to make sure there's 100 pixels between the first text group and the second, there are still ways to manage that without building and compositing multiple labels.
I just put my workaround together and it seems to work perfectly.
There are many approaches to get various tasks done with ImageMagick. If you're satisfied with how a particular way works, it is the right way for you.
I use Windows 7 Ultimate x64 SP1 and ImageMagick-7.0.1-Q16, 64 bits
The IM7 command will be "magick" not "convert".

Re: Label interword-spacing fit, but multiple spaces in text

Posted: 2016-05-11T07:12:58-07:00
by queensoft
I was able to extract the desired pointsize and it worked.

Yes, underscore may be different size than space. But I'm not that picky, I do not need 1000% exact perfect match.
I just ran my program about 80 times and the result was perfect each time.
In my case, debug result matched the label pointsize perfectly.
I need text to be justified both sides left and right:
- left:www.google.com
- right: CALL (555) 123-4567
Using different fonts means that the middle gap is always different size.
Come to think of if, 3rd time I'm writing/editing this, it also seems weird to me, there's no good way to justify this text the way I want it.
I mean, how big do you make that middle gap ?
But, anyways, the workaround works perfectly :)

I was wondering why IM7 does not have the convert.exe anymore !!!
So I just downloaded the portable version and this one had the convert.exe
I also did a quick search (really quick) for IM7 changelog / script breaking changes / missing convert.exe.... but found nothing useful.
I will use magick.exe in the future.

Re: Label interword-spacing fit, but multiple spaces in text

Posted: 2016-05-11T07:59:23-07:00
by snibgo
I assume you installed on Windows.
At installation, did you tick the option for:

Code: Select all

"Install legacy utilities (e.g. convert)"