【发布时间】:2021-04-27 00:26:41
【问题描述】:
我正在尝试使用Intervention 打开图像
use Intervention\Image\ImageManagerStatic as Image;
$image = Image::make('https://via.placeholder.com/300/09f/fff.png');
但是当转储它时,返回的只是空值。
如果我 dd 实际图像
dd(file_get_contents('https://via.placeholder.com/300/09f/fff.png'));
我明白了
b"ëPNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x01,\x00\x00\x01,\x04\x03\x00\x00\x00ïSôF\x00\x00\x00\ePLTE\x00Ö ▀‗ ƒÏ \x1FÑ \x7F╠ ┐Õ _┐ ?▓ ¹\\t\r\x00\x00\x03¸IDATx ▶"
我试过了
$image = Image::make(file_get_contents('https://via.placeholder.com/300/09f/fff.png'));
但是 dd($image) 也返回 null。
我也试过
private function get_content($URL){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $URL);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$image = Image::make($this->get_content('https://via.placeholder.com/300/09f/fff.png'));
dd($image) 也为此返回 null。
您对如何使用此库打开图像有任何想法吗?我正在使用 Lumen,并尝试使用 Docker 和 php artisan serve 来运行它。
会不会和 Composer 有关系?
更新
我也想知道是不是司机的原因。 Gd 是图像干预的默认值。我确保在 php.ini 中启用了和 imagick,并尝试了 gd(默认)和 imagick 作为驱动程序
Image::configure(['driver' => 'imagick']);
但 dd($image) 保持为空。
此外,检查 storage/logs/laravel.log 不会显示任何内容。
最终更新
解决方案原来与作曲家有关。我删除了 composer.lock 和供应商的内容并执行了全新的 composer install 并且 $image 现在显示了所需的数据。
【问题讨论】:
-
allow_url_fopen是 php.ini 中的设置,而不是函数。你真的可以访问那个 URL 吗?只需执行var_dump(file_get_contents('url-to-the-file'));并在尝试将其传递给其他函数之前查看您返回的内容。 -
@Magnus 已更正,谢谢。
-
@MagnusEriksson 我已经用 file_get_contents 的转储更新了帖子
标签: php lumen intervention