Cant use caption (need wrapped text)?

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
lusoplayer
Posts: 2
Joined: 2012-04-12T08:37:25-07:00
Authentication code: 8675308

Cant use caption (need wrapped text)?

Post by lusoplayer »

Hello,

I have the following code (used in PHP):

Code: Select all

exec(
            'convert -extent '.$width.'x'.$height.' gradient: -sigmoidal-contrast 6,45% \
            '.$imgBackground.' \
            +repage \
            -font "'.$font.'" \
            -fill "'.$fontColor.'" -pointsize '.$text_size.' -gravity "'.$text_align.'" \
            -draw "text 1,0 ''.$text.''" \
            '.$userLocal.''
        	);
But this does not allows me to use text wrapping. I read it needs to be with caption.

However, I have tried to place caption on the code in diferent places, but I cant make it work.

Any help?

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

Re: Cant use caption (need wrapped text)?

Post by fmw42 »

You have to create an image for your text with caption: and then composite it over your other image where you want it to be. You can also use line feeds \n to make the text break where you want it in -draw, I think.

Try this:

convert logo: \( -size 100x100 -background none -fill black caption:"THIS IS A TEST" \) \
-geometry +200+200 -compose over -composite logo_text.png
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Cant use caption (need wrapped text)?

Post by anthony »

Your options are a little out of order, and IMv7 would produce a 'no image to operate on' error on the VERY first option!!!

Read or create an image before trying to operate (in this case -extent) them.

Second you create a gradient but do not give a size for that gradient image!
And that IS an error 'must specify image size'! As such the command you have given will do nothing!!!!

You should try to log and read error messages!!!

How to fix... Replace -extent with -size as a starting point!

Finally you don't provide (or better still substute for us) what $imgBackground is!
Is that an image? what size? Why do you create a background then try to read in a backgroudn image? is it JPEG? (which means no transparency channel has been set).

I think I'll stop there, You seem to need some time with an actal command line first.

But do read Fred's response to your textual query, rather that the broken example code.


Applogies if sounded a little rude. I do not mean to be. My only excuse is that it is approaching midnight here in the land down under. Well applogies. Good Night.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
lusoplayer
Posts: 2
Joined: 2012-04-12T08:37:25-07:00
Authentication code: 8675308

Re: Cant use caption (need wrapped text)?

Post by lusoplayer »

Thanks for the answers.

I am trying to use an image as background of a text. So basically, write a text over an image in background.

This image size is not important, so let's say... I want to have an image with 200x200px and put some background into that space (which can be a image with 600x300px)... and write a text over.

Using -size did resize it, and I wanted to keep width X height fixed... so I did try with -extend.

in the solution given by fmw42, I did not understand how to use an image on the background.

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

Re: Cant use caption (need wrapped text)?

Post by fmw42 »

see my example

convert logo: \( -size 100x100 -gravity center -background none -fill black caption:"THIS IS A TEST" \) \
-gravity northwest -geometry +200+200 -compose over -composite logo_text1.png

If you want the logo: padded with more space, say to 1000x1000

Then do

convert \( logo: -gravity center -background white -extent 1000x1000 \) \
\( -size 100x100 -gravity center -background none -fill black caption:"THIS IS A TEST" \) \
-gravity northwest -geometry +380+460 -compose over -composite logo_text2.png
Post Reply