Wordwrap problem with caption

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
kleinstadtmc

Wordwrap problem with caption

Post by kleinstadtmc »

hi

i try to create a pic with text over a php input textarea field
most of all it works but i have a problem with wordwraps

the wordwraps wich the user type in with the enter key works

but the automaticaly wordwrap does not work in every situation
some times it breaks the line after two words - but there is enough space for
the rest of the letters... so normaly it has not to break the line...

can sombody help me?
here is my code:

Code: Select all

convert -size 328x226 -background white -font comic.ttf -pointsize 6 -fill black caption:"This is a sample text. How do you like it?\n\nBut I have a problem with wordwraps..." pic.jpg
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Wordwrap problem with caption

Post by anthony »

Make sure you have a later version of IM, there has been bug fixes for this...

Comic font was installed (the "imagick_type_gen" script named the font "ComicSans") trying....

Nope no problems with latest version. I get two small 6point lines
of double spaced text on a largish image. No word wrapping has been applied
or was needed for that point size.

I also tried at other point sizes like 20, 19, 18, etc.., and all works well.
It only word wraps if the next word + pre-spacing' fits on the line.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
kleinstadtmc

Re: Wordwrap problem with caption

Post by kleinstadtmc »

i think i have version 6.1.8

how can i use the imag_type_gen?
how should i write the code?

thank you for your help...
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Wordwrap problem with caption

Post by anthony »

See the comments at the top of the script (it is for UNIX users)
Also see http://www.imagemagick.org/Usage/#font
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
kleinstadtmc

Re: Wordwrap problem with caption

Post by kleinstadtmc »

ok my webmaster will install the latest version - then we will see...

but i have another problem
i try to resize a photo and put it into a empty canvas
and my problem is to give the photo a new size (change the position works)

here is my code...

Code: Select all

/usr/bin/convert -size 350x248 xc:skyblue \ -page 455x303+50+40 photo.jpg \ -flatten final.jpg
kleinstadtmc

Re: Wordwrap problem with caption

Post by kleinstadtmc »

if fix it myself - now i use this code:

Code: Select all

/usr/bin/convert -size 350x248 xc:skyblue \ photo.jpg -geometry 385x256+40+40 -composite \ final.jpg
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Wordwrap problem with caption

Post by anthony »

Yes -geometry is the right solution.

The -page does NOT resize images. It defines the images 'virtual canvas' or the area on which the image sits, and an offset in that area. It has nothing to do with the size of the actual image itself.

NOTE: a -geometry offset is only using for composition, and has nothing to do with virtual canvas offsets, which image composition ignores, except in a "-layers composite" which is designed for use with animations with image offsets.

The size component of -geometry purely an 'odd' way of resizing just the last image, rather than all the images in the current image sequence.

And finally -geometry composition offsets are -gravity effected, while -page offsets are not.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
kleinstadtmc

Re: Wordwrap problem with caption

Post by kleinstadtmc »

hhmmm... i thought it works but there is once again a problem

i use this code:

Code: Select all

/usr/bin/convert -size 350x248 xc:skyblue \ photo.jpg -geometry 385x256+100+70 \ -composite final.jpg
i want the final size to be 350x248 but the final size in this case is 361x256
what is the problem?

i want to have a empty cavas with the size 350x248 and then put the photo into it in a position i want (in this case +100+70) in a smaler size ( in this case 385x256) so that in this case a part of the photo is cutted an a part of the canvas is empty...
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Wordwrap problem with caption

Post by anthony »

Im is preserving the aspect ratio of the image. That is the horisontal and vetical scale is kept the same so circles remain circles.

To tell IM to ignore aspect, add a '!' flag.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
kleinstadtmc

Re: Wordwrap problem with caption

Post by kleinstadtmc »

now i have the version 6.3.5 and the wordwrap problem is fixed - now it works perfect

but i still have problems with resizing the image

if i use this code...

Code: Select all

/usr/bin/convert photo.jpg -resize 350x248 final.jpg
... imagemagick do nothing - it saves no final.jpg
if i use a smaller version of photo.jpg i still get no final.jpg

if i use this code with the photo in original large version...

Code: Select all

/usr/bin/convert photo.jpg -geometry 350x248+0+0 final.jpg
... imagemagick save nothing...
if i use the same code with the smal version of the photo it saves a final.jpg but in the original
size of the smaler photo... if i don´t write the +0+0 i get no final.jpg

i don´t no what to do - i will get crazy -
do i missunderstand the syntax?
but in the usage they say for resizing - my first code must work... but i get no image back...
what should i do?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Wordwrap problem with caption

Post by anthony »

The syntax is fine, and from what you describe it should be working.

Do you get any errors? It is very weird if you aren't.

What does

Code: Select all

identify photo.jpg
give you? Also try the -verbose option.

try adding a -identify into the convert command before and after the -resize to see what IM thinks it has in memory.

If you are still having problems try the convert with a -debug all and try to see what is going wrong.

Could you have more than one copy of IM installed. Perhaps the library files are getting mixed up.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
kleinstadtmc

Re: Wordwrap problem with caption / and with resize jpgs

Post by kleinstadtmc »

ok i look for errors...

but i have tried out something

if i put a jpg from istockphoto on my webspace and try to resize it - it dont works

but if i take the jpg and open it in my photoshop and save it with the "save for web" modul
and put it on my webspace - now it works with IM... and it doesnt matter if i save it with a large or small file or pic size

but if i try the same with the standard save as jpg in photoshop - it doesnt work with IM - and it doesnt matter if i save it with a large or small file or pic size

could this be the problem?
-----------------------------------------
i have open a new topic because this topic subject is not any longer what it is about my problem
viewtopic.php?f=1&t=9185
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Wordwrap problem with caption

Post by anthony »

Are you sure the photo is not being resized. You may be seeing the smaller photo at scaled by the viewer to a specific sized based on the photos meta-data.

I have been caught out by this until I noticed the 'magnification' for the viewed image has changed.

Remember -resize only resizes the image in terms of pixels. You may want -resample which resizes not only the image by pixels but also by the image resolution. Or you may like to set the resolution using -density before actually writing the new jpeg image.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply