hw to offset text from the top of an image and give it a text alignment of center
Re: hw to offset text from the top of an image and give it a text alignment of center
kk fmw, let me try the above code first however could you point to some of those Windows PHP users.
the spacing between the text is causing lots problem. hw can i solve these? any PHP user home??
the spacing between the text is causing lots problem. hw can i solve these? any PHP user home??
Last edited by dt59 on 2017-08-27T14:23:08-07:00, edited 1 time in total.
Re: hw to offset text from the top of an image and give it a text alignment of center
pls can somebody explain -trim, +repage and -smush.
and why the signs - and +.
and why the signs - and +.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: hw to offset text from the top of an image and give it a text alignment of center
-trim removes constant colors around the image. The +repage is to make sure the output dimensions are the same as the trimmed dimension; that is remove the virtual canvas that holds the original size and crop offset. It is the same as -repage +0+0. The -smush put an offset between the two images vertically. The +smush does the same horizontally. It is like append except it puts space between them.
See http://www.imagemagick.org/script/comma ... ptions.php for each operator and also
http://www.imagemagick.org/script/comma ... .php#smush
http://www.imagemagick.org/Usage/crop/#trim
For novices, see
viewtopic.php?f=1&t=9620
http://http://www.imagemagick.org/scrip ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
See http://www.imagemagick.org/script/comma ... ptions.php for each operator and also
http://www.imagemagick.org/script/comma ... .php#smush
http://www.imagemagick.org/Usage/crop/#trim
For novices, see
viewtopic.php?f=1&t=9620
http://http://www.imagemagick.org/scrip ... 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
hello Fred have read some of these stuff here on IM bt don't have a full understanding as the way u just briefly explained it. am sorry for my newbie questions.
please Wat the difference between xc and the background image operator??
please Wat the difference between xc and the background image operator??
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: hw to offset text from the top of an image and give it a text alignment of center
xc: is the same as canvas: Both are used to create a color image in combination with -size. They are called pseudoimages, since the are used internally to imagemagick. See http://www.imagemagick.org/script/formats.php#pseudo
Re: hw to offset text from the top of an image and give it a text alignment of center
well explained am beginning to understand hw IM is working. i can now create some IM command on my own, thanks fred for the kind lectures.
finally have fixed the spacing problem by using /"your string here/"
fred is their a way i could set the height and width of the red border so that i can truncate any text beyond the border
finally have fixed the spacing problem by using /"your string here/"
fred is their a way i could set the height and width of the red border so that i can truncate any text beyond the border
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: hw to offset text from the top of an image and give it a text alignment of center
Do you mean the box size or the thickness of the lines?dt59 wrote:fred is their a way i could set the height and width of the red border so that i can truncate any text beyond the border
The way they both are set is from the command:
Code: Select all
-bordercolor white -border 10 -bordercolor red -border 10
Is that what you want?
Re: hw to offset text from the top of an image and give it a text alignment of center
box size, i want to truncate the text if the text entered by the users is longer than box size.
Last edited by dt59 on 2017-08-27T22:58:29-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: hw to offset text from the top of an image and give it a text alignment of center
The box size cannot be made smaller than the trimmed composite image (to remove text), unless you crop it specifically after the trim and composite. The way my code works is to create a text image and trim to its bounding box.. Create a second text image and trim to its bounding box. Then smash them with some space to append them. Then add so white border to pad the area around both text. Then add the red border. Perhaps you can explain more what you want and show a diagram or example.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: hw to offset text from the top of an image and give it a text alignment of center
Why do you want to trim off text?
Re: hw to offset text from the top of an image and give it a text alignment of center
i want to truncate the text if the text entered by the users is longer than box size, from what am seeing now, if the user enter a text longer than box the box then extent to the side of the 500x500 background.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: hw to offset text from the top of an image and give it a text alignment of center
If you want a specific box size then you need to use my other code that I showed earlier that uses -annotate and -draw. With -draw, you can specify the box size. But the text can extend outside the box if you do not pick the right font size. So I am not sure this is what you want.
To draw a box of just the right size. You need to create a white background image of that size, use annotate to add your text. If the text is too long, it will be truncated by the background image. Then add your color border around that. You will have to make your background image sized to account for the thickness of the border you add at the end. Then composite that at the desired location in your larger 500x500 background
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
Re: hw to offset text from the top of an image and give it a text alignment of center
i will want to maintain the center text alignment by using the gravity = center, because i don't known the length of the text the user is going to type in. therefore i may not want to manually tweak the position of the text. however i will want the text to be at the center of the box. is that possible??
hope you understand wat am trying to do, fred?
hope you understand wat am trying to do, fred?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: hw to offset text from the top of an image and give it a text alignment of center
Unfortunately, that is hard. The caption: option will allow the text to wrap and center. But then it will never exceed the width of the image it creates, but it could exceed the height. The -annotate option allows you to write individual lines of text, but you have to position them so that they center the way you want. Similar with -draw. I do not know of a way to have multiple lines of text and have them cropped by the image and centered at the same time.
You may look further into PANGO: and see if it can do that. I am not an expert on PANGO and it has its own markup language.
See http://www.imagemagick.org/Usage/text/#pango and http://www.pygtk.org/docs/pygtk/pango-m ... guage.html
You may look further into PANGO: and see if it can do that. I am not an expert on PANGO and it has its own markup language.
See http://www.imagemagick.org/Usage/text/#pango and http://www.pygtk.org/docs/pygtk/pango-m ... guage.html
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: hw to offset text from the top of an image and give it a text alignment of center
Best I can suggest is to crop the code I gave you first. See the red code and choose your gravity setting and crop WxH.
<?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 -gravity ZZZ -crop WxH +repage -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>";}
?>
<?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 -gravity ZZZ -crop WxH +repage -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>";}
?>