Page 2 of 4
Re: hw to offset text from the top of an image and give it a text alignment of center
Posted: 2017-08-26T00:48:08-07:00
by dt59
fmw42 wrote: ↑2017-08-25T16:35:14-07:00
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>";}
?>
fm, what are u trying to do on line 6 of ur code, there seems to be problem there i mean syntax error
Re: hw to offset text from the top of an image and give it a text alignment of center
Posted: 2017-08-26T10:06:10-07:00
by fmw42
I am sending stderr to stdout and saving (errors) messages in $out. Then use foreach to display that to your web page when running the PHP code.
Re: hw to offset text from the top of an image and give it a text alignment of center
Posted: 2017-08-26T13:44:43-07:00
by dt59
fmw42 wrote: ↑2017-08-26T10:06:10-07:00
I am sending stderr to stdout and saving (errors) messages in $out. Then use foreach to display that to your web page when running the PHP code.
but the above code is not working. showing me error on that same line. pls help me fm i really need to make these work. if possible just review that ur above code. pls
Re: hw to offset text from the top of an image and give it a text alignment of center
Posted: 2017-08-26T14:03:38-07:00
by Bonzo
If you are on a Linux system you need to escape the ( ) like \( \)
Re: hw to offset text from the top of an image and give it a text alignment of center
Posted: 2017-08-26T14:44:05-07:00
by snibgo
This line?
Code: Select all
exec("$ou" 2>&1", $out, $returnval);
Quotes usually come in pairs. Perhaps:
Code: Select all
exec("$ou 2>&1", $out, $returnval);
Re: hw to offset text from the top of an image and give it a text alignment of center
Posted: 2017-08-26T15:09:00-07:00
by fmw42
snibgo wrote:exec("$ou 2>&1", $out, $returnval);
Yes, thanks snibgo. I missed the extra quote.
Re: hw to offset text from the top of an image and give it a text alignment of center
Posted: 2017-08-26T20:44:50-07:00
by dt59
you men are genius worked like charm i can now see my errors and fix them, one after the other. thanks fmw for ur smart code, snibgo and bonzo big thanks. but there seems to be alot errors:
magick: unable to open image '(-background': No such file or directory @ error/blob.c/OpenBlob/3109.
magick: no decode delegate for this image format `' @ error/constitute.c/ReadImage/509.
magick: no image to apply a property "%w" @ warning/property.c/GetMagickPropertyLetter/2561.
magick: unknown image property "%w" @ warning/property.c/InterpretImageProperties/3499.
magick: no image to apply a property "%h" @ warning/property.c/GetMagickPropertyLetter/2449.
magick: unknown image property "%h" @ warning/property.c/InterpretImageProperties/3499.
magick: no image to apply a property "%m" @ warning/property.c/GetMagickPropertyLetter/2480.
magick: unknown image property "%m" @ warning/property.c/InterpretImageProperties/3499.
i don't understand why the first error is showing; and most importantly the other errors. Can somebody 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-26T20:51:53-07:00
by dt59
Bonzo wrote: ↑2017-08-26T14:03:38-07:00
If you are on a Linux system you need to escape the ( ) like \( \)
no, am using window, do i still need to escape if yes hw do i escape
Re: hw to offset text from the top of an image and give it a text alignment of center
Posted: 2017-08-26T21:04:52-07:00
by fmw42
You do not need escapes in your code here. But for windows, escapes are the ^ character.
Re: hw to offset text from the top of an image and give it a text alignment of center
Posted: 2017-08-26T22:15:25-07:00
by snibgo
dt59 wrote:magick: unable to open image '(-background'
Like I said upthread:
snibgo wrote:You need a space after each "(".
As you are running PHP, you should follow PHP escaping rules, not Microsoft BAT or CMD escaping rules.
Re: hw to offset text from the top of an image and give it a text alignment of center
Posted: 2017-08-26T22:21:06-07:00
by fmw42
snibgo wrote:You need a space after each "(".
I missed that, too. Thanks, snibgo.
Re: hw to offset text from the top of an image and give it a text alignment of center
Posted: 2017-08-27T12:41:55-07:00
by dt59
its not still working, can somebody please help me fix it. here is code:
Code: Select all
$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";
//echo $ou.'<br/>';
echo (exec("$ou 2>&1", $out, $returnval).'<br/>');
//var_dump($out);
if ($returnval == '0'){
echo "Image created sucessfully";
}
else{
echo '<h1>There was an error when trying to generate images such as:</h1>';
foreach($out as $text){echo
"$text<br>";
}
}
Re: hw to offset text from the top of an image and give it a text alignment of center
Posted: 2017-08-27T13:29:52-07:00
by fmw42
try this. note I put spaces between your ( and the first character. That is what snibgo was trying to tell you.
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>";}
?>
I do not use PHP much so an not sure about all your quotes nor the outer quotes needed by PHP. One of the other PNP users may have to help if this does not work.
Re: hw to offset text from the top of an image and give it a text alignment of center
Posted: 2017-08-27T13:57:24-07:00
by dt59
hm, two errors are still showing
:
magick: unable to open image 'first': No such file or directory @ error/blob.c/OpenBlob/3109.
magick: no decode delegate for this image format `' @ error/constitute.c/ReadImage/509.
what can i do next...
Re: hw to offset text from the top of an image and give it a text alignment of center
Posted: 2017-08-27T14:02:27-07:00
by fmw42
dt59 wrote: ↑2017-08-27T13:57:24-07:00
hm, two errors are still showing
:
magick: unable to open image 'first': No such file or directory @ error/blob.c/OpenBlob/3109.
magick: no decode delegate for this image format `' @ error/constitute.c/ReadImage/509.
what can i do next...
The first message is coming because it is seeing the text as separate words and ignoring the quotes. So it see the text as "my" and then thinks first is a new image. Sorry I do not know what to tell you. I have heard this happen before on windows PHP, but do not know how to fix it. You could try to escape the single quotes or escape double quotes. Probably the latter. Windows may not like single quotes.
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>";}
?>
Sorry, I am not a Windows user. So you may need more help from Windows PHP users.