我目前正试图通过Imagemagick做一个小型图像处理类型项目来教自己PHP。为了从基础开始,我写了一些简单的代码来读取图像并将其转换为PNG。当在URL上使用Imagick的readImageFile时,如何解决“检测到无效的CRT参数”错误?
但是,虽然我能够从本地图像文件读取,但我完全无法从URL中读取图像,因为它在URL上调用readImageFile()时崩溃,并且出现以下错误:
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
我花了最后一个小时的谷歌搜索的方式来解决这个问题,但没有成功,我已经能够找到的唯一的领先是Error in using readImage function (Imagick)。然而,与这个问题不同,我完全可以使用readImage,甚至可以在本地文件上使用readImageFile,而不是在图像URL上。
从那里唯一的评论,它似乎可能是一个特定于Windows的错误,但我想知道如果任何人碰巧能够确认/否认这一点和/或建议一种方法来解决CRT参数错误?
作为参考,我写的代码如下:
<?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();
?>
此外,我运行64位Windows 7,以及我使用XAMPP 1.7.7(其使用PHP 5.3.8),我最初使用these instructions安装Imagemagick 6.6.4。 (虽然我用Imagemagick 6.6.2替换了6.6.4版本,但是根据评论者here的建议,它没有固定任何东西。)
哥们我也有同样的问题:) – GorillaApe