Page 1 of 4

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

Posted: 2017-08-14T02:24:29-07:00
by dt59
hw to offset text from the top of an image and give it a text alignment of center just like the image in the link explain what am trying to do
https://drive.google.com/open?id=0Bzloe ... 2JwSW8ybkU

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

Posted: 2017-08-14T02:36:26-07:00
by snibgo
I don't understand what you want. "-annotate +X+Y hello" will offset the string by +X+Y relative to the gravity setting. With "-gravity North", this is relative to the top-centre of the image.

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

Posted: 2017-08-14T04:14:19-07:00
by dt59
i will want an offset from the top of the image not relative to the gravity setting, however i may want to use the gravity settings for my text alignment meaning if i want a text to be align left, i will use the gravity settings of west am trying to acheive something like these :
https://drive.google.com/open?id=0Bzloe ... 2JwSW8ybkU

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

Posted: 2017-08-14T08:59:15-07:00
by dt59
somebody should please help me, pls.

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

Posted: 2017-08-14T09:57:56-07:00
by fmw42
Try this. Create each line of text using label:. Then append them using -smush to put the 20 pixel spacing. Then composite that over a white background at your desired location. Adjust the border spacing and color and text color and font and point size as desired.

Code: Select all

convert -background white -fill black -gravity center -pointsize 36 label:"my first text" -trim +repage tmp1.png
convert -background white -fill black -gravity center -pointsize 36 label:"center text" -trim +repage tmp2.png
convert tmp1.png tmp2.png -gravity center -smush +20 -bordercolor white -border 10 -bordercolor red -border 10 tmp3.png
convert -size 500x500 xc:white tmp3.png -geometry +57+146 -compose over -composite text_result.png
Image

In one command line in unix format it would be:

Code: Select all

convert \
\( -background white -fill black -gravity center -pointsize 36 label:"my first text" -trim +repage \) \
\( -background white -fill black -gravity center -pointsize 36 label:"center text" -trim +repage \) \
-gravity center -smush +20 -bordercolor white -border 10 -bordercolor red -border 10 \
\( -size 500x500 xc:white \) +swap -gravity northwest -geometry +57+146 -compose over -composite text_result.png

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

Posted: 2017-08-16T13:22:01-07:00
by dt59
@fmw, u're using the label image operator, could t be possible to use the annotate IO.i really appreciate ur suggest above.

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

Posted: 2017-08-16T15:03:05-07:00
by fmw42
You can use annotate, but you need to do one annotate for each line of text and provide the exact location where you want the text to be located. You can chain the two annotates in the same command line. But -annotate does not draw boxes. So you would have to add a -draw "rectangle x1,y,1 x2,y2" to add that. My label command seems the easier way to go so that I did not have to located each line of text separately and draw the box separately.

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

Posted: 2017-08-17T01:14:44-07:00
by dt59
putting bracket around command, what does it help u to achieve? and pls is there any book that could be recommend as to teach me, hw to write imagemagick command. Am using IM for a project and its taking me time to learn and understand the flow of the script.
could u pls show me an example IM command of ur last comment.

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

Posted: 2017-08-17T09:42:41-07:00
by fmw42
Using parentheses, allows you to do multiple separate commands in the same command line without the settings affecting subsequent parts in other parentheses. See http://www.imagemagick.org/Usage/basics/#parenthesis

Here is the command written with annotate and draw, but I had to tweak it several times to get it aligned properly. The advantage of the label method is that it aligns automatically.

Code: Select all

convert -size 500x500 xc:white \
-fill black -pointsize 36 -font arial -gravity northwest \
-annotate +78+167 "my first text" \
-annotate +85+213 "center text" \
-fill none -stroke red -strokewidth 10 \
-draw "rectangle 65,155 275,263" -alpha off \
text_result2.png
Image

See
http://www.imagemagick.org/Usage/text/#annotate
http://www.imagemagick.org/Usage/draw/#primitives

All the books are very old. See http://www.imagemagick.org/script/sitemap.php#help

But the best resources are:

viewtopic.php?f=1&t=9620http://http://w ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/

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

Posted: 2017-08-25T14:14:55-07:00
by dt59
sorri am replying late @fm pls i tried to test the code and has not been working. here is wat have tried:

Code: Select all

<?php
$ou = "magick "; 
$ou .= "(-background white -fill black -gravity center -pointsize 36 label:'my first text' -trim +repage ) ";
$ou .= "(-background white -fill black -gravity center -pointsize 36 label:'center text' -trim +repage ) ";
$ou .= "-gravity center -smush +20 -bordercolor white -border 10 -bordercolor red -border 10 ";
$ou .= "(-size 500x500 xc:white ) +swap -gravity northwest -geometry +57+146 -compose over -composite text_result.png";
exec("$ou");
?>
its not working. can u pls help me fix it.
thank u very much i so much appreciate your time

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

Posted: 2017-08-25T14:39:34-07:00
by snibgo
You need a space after each "(".

I suggest you capture and report errors.

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

Posted: 2017-08-25T15:51:53-07:00
by dt59
@snibgo , pls hw do i capture and report errors. can u give me the snippet to report error.

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

Posted: 2017-08-25T15:56:08-07:00
by snibgo
I don't use PHP. There are examples on these forums.

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

Posted: 2017-08-25T16:35:14-07:00
by fmw42
try this

Code: Select all

<?php
$ou = "magick "; 
$ou .= "(-background white -fill black -gravity center -pointsize 36 label:'my first text' -trim +repage ) ";
$ou .= "(-background white -fill black -gravity center -pointsize 36 label:'center text' -trim +repage ) ";
$ou .= "-gravity center -smush +20 -bordercolor white -border 10 -bordercolor red -border 10 ";
$ou .= "(-size 500x500 xc:white ) +swap -gravity northwest -geometry +57+146 -compose over -composite text_result.png";
exec("$ou 2>&1", $out, $returnval);
foreach($out as $text)
{echo "$text<br>";}
?>
FIXED to remove the extra quote in the exec line

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

Posted: 2017-08-26T00:37:52-07:00
by dt59
snibgo wrote: 2017-08-25T15:56:08-07:00 I don't use PHP. There are examples on these forums.
can you please point to one of them