I'm currently trying to teach myself PHP by doing a small image-processing type project with Imagemagick. To start off with the basics, I wrote some simple code to read in an image and convert it to a PNG.
However, while I'm able to read from local image files, I am completely unable to read in images from URLs, as it crashes when I call readImageFile() on the url, and I get the following error:
Fatal error: Uncaught exception 'ImagickException' with message 'Invalid CRT parameters detected' in C:\xampp\htdocs\imagepractice\imagemagicktest.php:8 Stack trace: #0 C:\xampp\htdocs\imagepractice\imagemagicktest.php(8): Imagick->readimagefile(Resource id #3) #1 {main} thrown in C:\xampp\htdocs\imagepractice\imagemagicktest.php on line 8
I've spent the last hour Googling for a way to fix this, to no avail, and the only lead I have been able to find is Error in using readImage function (Imagick). However, unlike that issue, I am perfectly able to use readImage, and I'm even able to use readImageFile on local files, just not on image URLs.
From the only comment there, it seems that it may possibly be a bug specific to Windows, but I was wondering if anyone happens to be able to confirm/deny this and/or suggest a way to fix the CRT parameter error?
For reference, the code I wrote is below:
<?php
$im = new Imagick();
//$im->newPseudoImage(1000, 1000, "magick:rose"); //this works!
//$im->readImage("images\\wheels.jpg"); // this works!
$handle = fopen("http://www.google.com/images/srpr/logo3w.png", "rb");
$im->readImageFile($handle); //this line crashes!
fclose($handle);
$im->setImageFormat("png");
$type = $im->getFormat();
header("Content-type: $type");
echo $im->getImageBlob();
?>
In addition, I am running 64-bit Windows 7, and I am using XAMPP 1.7.7 (which uses PHP 5.3.8), and I initially installed Imagemagick 6.6.4 using these instructions. (Although I replaced the 6.6.4 version with Imagemagick 6.6.2 instead, as per the suggestion of a commenter here, which hasn't fixed anything.)