Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP Imagick-无法从文件句柄[XAMPP on Win10 x64]读取图像_Php_Xampp_Imagemagick_Imagick_Filehandle - Fatal编程技术网

PHP Imagick-无法从文件句柄[XAMPP on Win10 x64]读取图像

PHP Imagick-无法从文件句柄[XAMPP on Win10 x64]读取图像,php,xampp,imagemagick,imagick,filehandle,Php,Xampp,Imagemagick,Imagick,Filehandle,这个简单的代码块面临以下问题: $picstream = fopen($url, 'rb'); $picture = new Imagick(); try { $picture->readImageFile($picstream); } catch (ImagickExpection $e) { echo $e->getMessage(); } $url变量是指向JPEG图片的公共可访问url 然后我得到以下错误:“无法从文件句柄读取图像” 奇怪的是,如果我做一个s

这个简单的代码块面临以下问题:

$picstream = fopen($url, 'rb');
$picture = new Imagick();
try {
    $picture->readImageFile($picstream);
}
catch (ImagickExpection $e) {
    echo $e->getMessage();
}
$url
变量是指向JPEG图片的公共可访问url

然后我得到以下错误:“无法从文件句柄读取图像”

奇怪的是,如果我做一个
stream\u获取内容($picstream)
,然后
echo
使用
内容类型:image/jpeg
标题,我就能看到图像,因此
fopen
返回一个有效的资源

本地服务器已安装:

  • Apache 2.4.4
  • PHP 5.6.14(VC11)32位TS
  • ImageMagick-6.8.6-8-Q16-x86-dll
  • php_imagick-3.1.2-5.6-ts-vc11-x86
  • Windows 10 x64
同样奇怪的是,在Linux机器(Debian Jessie)中,我可以直接从
Imagick
构造函数打开URL,也可以通过这种方式读取流,但在Windows和XAMPP下我无法做到这一点。我不知道为什么会发生这种情况,因此想不出比
file\u put\u contents
解决方案更好的解决方案


有什么想法吗?我错过了什么

只需先下载文件,然后在本地打开即可。在ImageMagick中直接从打开的连接读取图像非常困难。为什么不
新建Imagick($url)
?但是@Danack是对的,在尝试将资源加载到内存之前,您应该在本地获取文件(加上验证和错误句柄)。
new Imagick($url)
在Win&XAMPP上提示“无法读取文件”错误,即使它在LAMP堆栈上工作。