Jump to content

Trying to use image magick with php but get a blank page.


00stuff

Recommended Posts

Hi guys I am trying to use image magick with php to draw an image but when i run the script it doens't show anything. All I get is an a blank page. Does anyone know if I am doing this right.

 

Here is my code.

<?php
echo "<pre>";
system("type convert"); 
echo "</pre>";
?>
<br />
<br />
<br />
<br />
<br />
<?php
exec("/usr/bin/convert -size 200x200 xc:black -stroke black -strokewidth 1 \\
-fill white -draw \"circle 100,100 100,10 \" \\
-fill black -draw \"circle 100,100 100,30 \" \\
-fill blue -draw \"circle 100,100 100,50 \" \\
-fill red -draw \"circle 100,100 100,70 \" \\
-fill yellow -draw \"circle 100,100 100,90 \" \\
-fill none -draw \"circle 100,100 100,20 \" \\
-fill none -draw \"circle 100,100 100,60 \" \\
-fill none -draw \"circle 100,100 100,80 \" \\
-fill none -draw \"circle 100,100 100,95 \" \\
-stroke white -fill none \\
-draw \"circle 100,100 100,40 \" circle.png");
?>

 

 

My results are these:

 

convert is /usr/bin/convert

 

 

I really need some help with this. I haven't been able to find anything online.

Link to comment
Share on other sites

Two options:

 

1. If you actually need an image file, like you're updating something infrequently, then only (re)create the image when it needs to be (re)created. As in, not on every page load like it will do now. Then add an referencing it to actually see it on the page.

 

2. Use passthru to call convert and make the program output the image data instead of save it to a file. Put this passthru() call it one script somewhere with appropriate header()s, then use an to reference that script.

header("Content-Type: image/png"); // according to whatever convert creates
passthru("/usr/bin/convert...");

?>


Just know that the image.php will create the image every single time it's called, so if the image doesn't change a lot (or at all) then this is wasteful.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.