Page 4 of 4

Re: hw to offset text from the top of an image and give it a text alignment of center

Posted: 2017-08-28T00:32:08-07:00
by dt59
hello fred, did u test the code. am having undesired result,check pls

Re: hw to offset text from the top of an image and give it a text alignment of center

Posted: 2017-08-28T10:40:29-07:00
by fmw42
When in doubt, separate the commands and look at each intermediate result to see what is happening.

Code: Select all

convert -background white -fill black -gravity center -pointsize 36 label:"my first text" -trim +repage tmp1a.png
convert -background white -fill black -gravity center -pointsize 36 label:"center text" -trim +repage tmp2a.png
convert tmp1a.png tmp2a.png -gravity center -smush +20 -bordercolor white -border 10 tmp3a.png
convert tmp3a.png -bordercolor red -border 10 tmp3b.png
convert -size 500x500 xc:white tmp3b.png -geometry +57+146 -compose over -composite text_resultA.png
convert tmp3a.png -format "%wx%h" info:
202x99
Image

In the above, I found the size of the text image before adding the red border. So I cropped it a bit smaller in width in the following.

Code: Select all

convert -background white -fill black -gravity center -pointsize 36 label:"my first text" -trim +repage tmp1a.png
convert -background white -fill black -gravity center -pointsize 36 label:"center text" -trim +repage tmp2a.png
convert tmp1a.png tmp2a.png -gravity center -smush +20 -bordercolor white -border 10 tmp3a.png
convert tmp3a.png -gravity northwest -crop 184x99+0+0 +repage -bordercolor red -border 10 tmp3b.png
convert -size 500x500 xc:white tmp3b.png -geometry +57+146 -compose over -composite text_resultB.png
Image


The above is likely not what you want as I mentioned above in my previous email. And as I said before, there is no easy way that I know to do what you want. Imagemagick cannot do both wrap and trim text that is too long.

So what I think you have to do is write the text with -annotate or -draw and place each line where you want on an image of the size you want for your box before adding the border. Then add the border. Then composite image in your 500x500 white background in the place you want. This is what I said in my last email message.

Please provide an example of the way you want your result to look.

Re: hw to offset text from the top of an image and give it a text alignment of center

Posted: 2017-08-29T00:11:18-07:00
by dt59
thanks Fred, is now working perfectly well as i expected. Am still learning anyway

Re: hw to offset text from the top of an image and give it a text alignment of center

Posted: 2018-12-15T00:17:08-07:00
by fmw42
PHP exec() is no different from command line imagemagick. You just put your command in the exec("....") area.

If you want other API, there is Imagick and Magickwand for PHP. See those forums on this web site.

See also http://www.rubblewebs.co.uk/index.php

Re: hw to offset text from the top of an image and give it a text alignment of center

Posted: 2018-12-15T15:54:26-07:00
by dt59
hello moderator, please is these forum topic still open, i will want to ask some questions base on my previous questions. permitted ?? or i should create a new topic.

Re: hw to offset text from the top of an image and give it a text alignment of center

Posted: 2018-12-15T16:22:11-07:00
by fmw42
Best to create a new topic after so long a time.

If it is really relevant, then you can link back to this topic in your new post.