0

gmagick is newer version of imagemagick with more set of features it is less resource intensive and fast but the problem is there is very few discussion about this wonderful tool on web i recently came across this on http://devzone.zend.com/1559/manipulating-images-with-php-and-graphicsmagick/ but i could not install it on windows machines cos phpize did not work so i tried some other way and some how managed to get on phpinfo page but i could not make it work further i colud not even open a single image with gmagick this is code i used

     <?php
     $path="gallery/img1.jpg";
     // initialize object
     $image = new Gmagick($path);
     echo $image;
    // read image file
   $file = 'gallery/img1.jpg';
   $image->readImage($file);
   echo '<img src="' . $file . '" width="200" height="150" /> <br/>';
   ?>

i used this code to instanstiate gmagick class and open image but i am geeting very big error as follows Fatal error: Uncaught exception 'GmagickException' with message 'Unable to open file (gallery/img1.jpg)' in C:\xampp\htdocs\junk\imgproc\imgproc1.php:4 Stack trace: #0 C:\xampp\htdocs\junk\imgproc\imgproc1.php(4): Gmagick->__construct('gallery/img1.jp...') #1 {main} thrown in C:\xampp\htdocs\junk\imgproc\imgproc1.php on line 4

sohaan
  • 637
  • 1
  • 10
  • 18

1 Answers1

3

A) To answer the question in your headline (that might lead other readers here):

Windows builds of the GraphicsMagick extension for PHP can be obtained here: http://valokuva.org/builds/

Check whether you need the thread-safe version or not by looking at a phpinfo(); output of your webserver. Look for the entry Thread Safety. In the entry PHP Extension Build you should also find the VC version that you need, e.g. API20090626,TS,VC9 for VC9.

Download the latest build that matches your conditions, put it into your PHP/ext directory and add it to your php.ini like this:

extension=php_gmagick_ts.dll

Remember to correct the name of the dll if you use the non-TS version.

Restart Apache and check phpinfo();. There should be a gmagick block now..

B) To correct the problem with your code:

  1. The Gmagick constructor does not expect a path as a parameter, but a full image filename (may include a path). Most often it is better to leave it empty and provide the file in the readImage() call.
  2. Try a full $path (starting at root) and use it in readImage() and writeImage():

Here is an example of a working piece of code:

<?php
// assuming this is the path to your code and to your image files
$path = 'C:\xampp\htdocs\junk\imgproc\';

$image = new Gmagick();
$file = 'img1.jpg';
$image->readImage($path.$file);

// The rest of your code does not make any use of the GM instance, 
// so I add something functional here: create a grayscale version and show it
$fileOut= 'img1_GRAY.jpg';
$image->setImageType(Gmagick::IMGTYPE_GRAYSCALE);
$image->writeImage($path.$fileOut);
$image->destroy();
echo "<img src='$fileOut' >";
?>

It should show a grayscale version of your image file.

Jpsy
  • 20,077
  • 7
  • 118
  • 115
  • Hey Jpsy, I've been having problems installing gmagick, maybe you could give me some advice? Here's my question on Stackoverflow: http://stackoverflow.com/questions/15098204/cant-install-gmagick-on-windows-7-xampp – misaizdaleka Feb 27 '13 at 09:39
  • @misaizdaleka: See my [answer to your question](http://stackoverflow.com/a/15111425/430742). – Jpsy Feb 27 '13 at 11:57