word wrapping issue

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
franco64

word wrapping issue

Post by franco64 »

Hi and apologies for this stupid question but i just can not figure out why this is happening

I have the following script

convert -size 720x480 xc:transparent -stroke black -strokewidth 1 -fill lightblue -colorspace RGB -depth 10 -font Hiragino-Kaku-Gothic-ProN-W3 -gravity North -pointsize 38 -annotate +0+10 'かいけいぼは きょねん かんさされました。' -annotate +0+60 'kaikeiboha kyonen kansasaremashita。' /Users/franco/Desktop/Japanese/Banking/Phrase20.png

now i know if i reduce the pointsize to 32 it will work for most but i still have some that are just cropped at the ends and i have 1000 of these graphics to generate and i really do not want to go through each one to change the pointsize. It seems that the word wrapping does not seem to work while some others do e.g

convert -size 720x480 xc:transparent -stroke black -strokewidth 1 -fill lightblue -colorspace RGB -depth 10 -font Hiragino-Kaku-Gothic-ProN-W3 -gravity North -pointsize 38 -annotate +0+10 'このかいしゃは ニューヨークしじょうに\nじょうじょうしました。' -annotate +0+100 'konokaishaha nyūyōkushijouni\njoujoushimashita。' /Users/franco/Desktop/Japanese/Banking/Phrase4.png

which use longer sentences

any help would be very appreciated

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: word wrapping issue

Post by fmw42 »

franco64 wrote:Hi and apologies for this stupid question but i just can not figure out why this is happening

I have the following script

convert -size 720x480 xc:transparent -stroke black -strokewidth 1 -fill lightblue -colorspace RGB -depth 10 -font Hiragino-Kaku-Gothic-ProN-W3 -gravity North -pointsize 38 -annotate +0+10 'かいけいぼは きょねん かんさされました。' -annotate +0+60 'kaikeiboha kyonen kansasaremashita。' /Users/franco/Desktop/Japanese/Banking/Phrase20.png

now i know if i reduce the pointsize to 32 it will work for most but i still have some that are just cropped at the ends and i have 1000 of these graphics to generate and i really do not want to go through each one to change the pointsize. It seems that the word wrapping does not seem to work while some others do e.g

convert -size 720x480 xc:transparent -stroke black -strokewidth 1 -fill lightblue -colorspace RGB -depth 10 -font Hiragino-Kaku-Gothic-ProN-W3 -gravity North -pointsize 38 -annotate +0+10 'このかいしゃは ニューヨークしじょうに\nじょうじょうしました。' -annotate +0+100 'konokaishaha nyūyōkushijouni\njoujoushimashita。' /Users/franco/Desktop/Japanese/Banking/Phrase4.png

which use longer sentences

any help would be very appreciated

Thanks
use caption: to get word wrapping

see http://www.imagemagick.org/Usage/text/#caption
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: word wrapping issue

Post by el_supremo »

Try this and see if it produces something close to what you want:

Code: Select all

convert -background none -stroke black -strokewidth 1 -fill lightblue -colorspace RGB -depth 10 -font Hiragino-Kaku-Gothic-ProN-W3  -gravity North -pointsize 38  ( -size 720x480 caption:'かいけいぼは きょねん かんさされました。' -trim ) ( -size 720x10 xc:transparent )  ( -size 720x480 caption:'kaikeiboha kyonen kansasaremashita。' -trim ) -append /Users/franco/Desktop/Japanese/Banking/Phrase20.png

Pete
franco64

Re: word wrapping issue

Post by franco64 »

many thanks for the responses. I seem to get an error message when trying the following

convert -background none -stroke black -strokewidth 1 -fill lightblue -colorspace RGB -depth 10 -font Hiragino-Kaku-Gothic-ProN-W3 -gravity North -pointsize 38 ( -size 720x480 caption:' かいけいぼは きょねん かんさされました。' -trim ) ( -size 720x10 xc:transparent ) ( -size 720x480 caption:' kaikeiboha kyonen kansasaremashita。' -trim ) -append /Users/franco/Desktop/Japanese/Banking/Phrase20.png

-bash: syntax error near unexpected token `('

any ideas would be great

thanks
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: word wrapping issue

Post by el_supremo »

I use Windows XP and I knew I would forget something when I converted that command back to Linux. The parentheses have to be escaped to get through bash.

Code: Select all

convert -background none -stroke black -strokewidth 1 -fill lightblue -colorspace RGB -depth 10 -font Hiragino-Kaku-Gothic-ProN-W3  -gravity North -pointsize 38 \( -size 720x480 caption:'かいけいぼは きょねん かんさされました。' -trim \) \( -size 720x10 xc:transparent \)  \( -size 720x480 caption:'kaikeiboha kyonen kansasaremashita。' -trim \) -append /Users/franco/Desktop/Japanese/Banking/Phrase20.png
Pete
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: word wrapping issue

Post by anthony »

Which is why I would like to see a PHP method to execute a command WITHOUT requiring it to be parsed by shell, though you will need to separate the arguments yourself. This is better for option controls as well as for security.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
franco64

Re: word wrapping issue

Post by franco64 »

unfortunately this don't work as i get the following

Image

What i should get is something like this

Image

but when i do the script i initially made i get and you clearly see that it crops at both ends

Image

I would like to just use 1 font size but if i decrease the font size for some it will make the others look small which i do not want

so anymore help would be grateful

Thanks
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: word wrapping issue

Post by el_supremo »

The result you want is essentially what I am getting on my system:

Image

but I suspect that you are using a Mac because the font you're using seems to be supplied with a Mac.
I'm using windows XP Pro SP3 and was testing using Bitstream-CyberCJK which is a free font that I found on the internet.
So, the differences we're seeing may be due to the different fonts or perhaps to a different version of ImageMagick.
Which version of ImageMagick are you using?
My system reports:

Code: Select all

    convert -version
Version: ImageMagick 6.4.4 2008-10-09 Q8 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2008 ImageMagick Studio LLC
Pete
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: word wrapping issue

Post by anthony »

Check that the spaces are really spaces and not 'hard' or 'no-break' spaces.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply