如何通过干预打开 URL 处的图像
How to open an image at a URL with Intervention
我正在尝试使用 Intervention
打开图像
use Intervention\Image\ImageManagerStatic as Image;
$image = Image::make('https://via.placeholder.com/300/09f/fff.png');
但是转储时,只返回 null。
如果我添加实际图像
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) 也 returns 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) returns 也为 null。
关于如何使用此库打开图像,您有什么想法吗?我正在使用 Lumen,并尝试使用 Docker 和 php artisan serve 运行 它。
会不会跟 Composer 有关系?
更新
我也想知道是不是驱动的问题。 Gd 是图像干预的默认值。我确保在 php.ini 中启用了 imagick 并尝试将 gd(默认)和 imagick 作为驱动程序
Image::configure(['driver' => 'imagick']);
但 dd($image) 保持为空。
- https://i.stack.imgur.com/xFYDy.png
- https://i.stack.imgur.com/1ruw4.png
此外,检查 storage/logs/laravel.log 没有显示任何内容。
最终更新
原来是composer相关的解决方案。我删除了 composer.lock 和供应商的内容并执行了全新的作曲家安装,$image 现在显示了所需的数据。
Image::make(file_get_contents('https://via.placeholder.com/300/09f/fff.png')
return 是 Image
对象。
因此您可以 return 带有 ->response()
的图像。
use Intervention\Image\ImageManagerStatic as Image;
Route::get('/test', function() {
return Image::make(file_get_contents('https://via.placeholder.com/300/09f/fff.png'))->response();
});
我正在尝试使用 Intervention
打开图像use Intervention\Image\ImageManagerStatic as Image;
$image = Image::make('https://via.placeholder.com/300/09f/fff.png');
但是转储时,只返回 null。
如果我添加实际图像
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) 也 returns 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) returns 也为 null。
关于如何使用此库打开图像,您有什么想法吗?我正在使用 Lumen,并尝试使用 Docker 和 php artisan serve 运行 它。
会不会跟 Composer 有关系?
更新
我也想知道是不是驱动的问题。 Gd 是图像干预的默认值。我确保在 php.ini 中启用了 imagick 并尝试将 gd(默认)和 imagick 作为驱动程序
Image::configure(['driver' => 'imagick']);
但 dd($image) 保持为空。
- https://i.stack.imgur.com/xFYDy.png
- https://i.stack.imgur.com/1ruw4.png
此外,检查 storage/logs/laravel.log 没有显示任何内容。
最终更新
原来是composer相关的解决方案。我删除了 composer.lock 和供应商的内容并执行了全新的作曲家安装,$image 现在显示了所需的数据。
Image::make(file_get_contents('https://via.placeholder.com/300/09f/fff.png')
return 是 Image
对象。
因此您可以 return 带有 ->response()
的图像。
use Intervention\Image\ImageManagerStatic as Image;
Route::get('/test', function() {
return Image::make(file_get_contents('https://via.placeholder.com/300/09f/fff.png'))->response();
});