PHP and ImageMagick
PHP and ImageMagick
I have a hosted site which has ImageMagick installed locally in my home directory and not compiled with PHP. How can I use that location in my PHP script (instantiate it from that location and not as a PHP complied module), or just call that location from PHP script?
Thanks for your help!
Marek
Thanks for your help!
Marek
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: PHP and ImageMagick
I am not a php expert, but you need to know the full path to IM convert (identify, mogrify etc) and use that in your PHP script to prefix convert in the exec command
try this and change the path to convert appropriate for its location on your system
<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>
You should get back the IM version information.
try this and change the path to convert appropriate for its location on your system
<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>
You should get back the IM version information.
Re: PHP and ImageMagick
I have a lot of php examples on my site see signature.
I do not think Imagemagick is compiled with php it is an external program whereas Imagick is.
Try running this and report what result you get:
I do not think Imagemagick is compiled with php it is an external program whereas Imagick is.
Try running this and report what result you get:
Code: Select all
<?php
echo "<pre>";
system("type convert");
echo "</pre>";
?>
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: PHP and ImageMagick
or perhaps
I am not sure of the difference between type and which. Both seem to identify the path to convert in my bash shell.
P.S. I tried both type convert and which convert as above and they both successfully report where IM lives.
Code: Select all
<?php
echo "<pre>";
system("which convert");
echo "</pre>";
?>
P.S. I tried both type convert and which convert as above and they both successfully report where IM lives.
Last edited by fmw42 on 2010-08-02T14:49:41-07:00, edited 1 time in total.
Re: PHP and ImageMagick
Ok, sweet at least we are getting somewhere...
Using:
Got a result of:
Version: ImageMagick 6.4.9-8 2009-03-05 Q16 http://www.imagemagick.org
Using:
Got a result of:
/usr/bin/convert
Now how can I call the binaries from PHP to get me going?
Edited: changed location of the binary in first code example
Using:
Code: Select all
<?php
exec("imagemagick/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>
Version: ImageMagick 6.4.9-8 2009-03-05 Q16 http://www.imagemagick.org
Using:
Code: Select all
<?php
echo "<pre>";
system("which convert");
echo "</pre>";
?>
/usr/bin/convert
Now how can I call the binaries from PHP to get me going?

Edited: changed location of the binary in first code example
Re: PHP and ImageMagick
You should now be able to:
Or neater when using long comands:
Code: Select all
exec("imagemagick/bin/convert input.jpg output.png");
Code: Select all
$cmd = "input.jpg -resize 200x200";
exec("imagemagick/bin/convert $cmd output.png");
Re: PHP and ImageMagick
I have a simple script:
<?php
try
{
/*** the image file ***/
$image = 'image.jpg';
/*** a new imagick object ***/
$im = new Imagick();
/*** ping the image ***/
$im->pingImage($image);
echo 'Imagick';
}
catch(Exception $e)
{
echo $e->getMessage();
}
?>[/code]
This code just throws the following error:
Fatal error: Class 'Imagick' not found in graphics/test2.php on line 13
I am assuming that it cannot instantiate a class but how do I point it to where ImageMagick is installed?
Thanks much folks!
Marek
<?php
try
{
/*** the image file ***/
$image = 'image.jpg';
/*** a new imagick object ***/
$im = new Imagick();
/*** ping the image ***/
$im->pingImage($image);
echo 'Imagick';
}
catch(Exception $e)
{
echo $e->getMessage();
}
?>[/code]
This code just throws the following error:
Fatal error: Class 'Imagick' not found in graphics/test2.php on line 13
I am assuming that it cannot instantiate a class but how do I point it to where ImageMagick is installed?
Thanks much folks!
Marek
Re: PHP and ImageMagick
This is where confusion comes in.
ImageMagick can be run from php as per my examples above as an external program. You are trying to use Imagick which is an API? and needs to be compiled with php ?
I would stick to Imagemagick with the comand line as there are a lot more options although you need to be extra careful of user input if users are allowed to submit to the code.
ImageMagick can be run from php as per my examples above as an external program. You are trying to use Imagick which is an API? and needs to be compiled with php ?
I would stick to Imagemagick with the comand line as there are a lot more options although you need to be extra careful of user input if users are allowed to submit to the code.
Re: PHP and ImageMagick
Bonzo, you are the Man! I will definitely stick to ImageMagick and will work on the examples you have. Is there a way to get in touch with you directly if I have any questions?
I am currently trying one example of yours to see if it will work on my hosted shared server.
Cheers and thanks much!
Marek
I am currently trying one example of yours to see if it will work on my hosted shared server.
Cheers and thanks much!
Marek