Page 1 of 1

Cant use caption (need wrapped text)?

Posted: 2012-04-12T08:40:40-07:00
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

Re: Cant use caption (need wrapped text)?

Posted: 2012-04-12T11:22:04-07:00
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

Re: Cant use caption (need wrapped text)?

Posted: 2012-04-13T06:33:52-07:00
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.

Re: Cant use caption (need wrapped text)?

Posted: 2012-04-14T11:50:56-07:00
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.

Re: Cant use caption (need wrapped text)?

Posted: 2012-04-14T12:02:15-07:00
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