fm, what are u trying to do on line 6 of ur code, there seems to be problem there i mean syntax errorfmw42 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>";} ?>
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
- 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
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
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
If you are on a Linux system you need to escape the ( ) like \( \)
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: hw to offset text from the top of an image and give it a text alignment of center
This line?
Quotes usually come in pairs. Perhaps:
Code: Select all
exec("$ou" 2>&1", $out, $returnval);
Code: Select all
exec("$ou 2>&1", $out, $returnval);
snibgo's IM pages: im.snibgo.com
- 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
Yes, thanks snibgo. I missed the extra quote.snibgo wrote: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
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
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
Last edited by dt59 on 2017-08-26T21:04:49-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
You do not need escapes in your code here. But for windows, escapes are the ^ character.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: hw to offset text from the top of an image and give it a text alignment of center
Like I said upthread:dt59 wrote:magick: unable to open image '(-background'
As you are running PHP, you should follow PHP escaping rules, not Microsoft BAT or CMD escaping rules.snibgo wrote:You need a space after each "(".
snibgo's IM pages: im.snibgo.com
- 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
I missed that, too. Thanks, snibgo.snibgo wrote:You need a space after each "(".
Re: hw to offset text from the top of an image and give it a text alignment of center
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>";
}
}
- 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
try this. note I put spaces between your ( and the first character. That is what snibgo was trying to tell you.
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.
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>";}
?>
Re: hw to offset text from the top of an image and give it a text alignment of center
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...
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...
- 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 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>";}
?>