我在我的一个项目中使用"intervention/image": "^2.5"。它运行良好,除了代码的一部分,其中我检索一个图像。
我一直得到一个Unable to init from given binary data错误,我不知道为什么。
这个文件是存在的,但我想不出来。
我的代码如下;
$path = '/image-storage/492/1/testimage.jpg';
$file = Storage::get($path);
ob_end_clean();
return Image::make($file)->response();下面是本地的filesystem.php配置
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],发布于 2022-06-08 21:53:06
Storage::get($path)将文件内容作为字符串返回,该字符串可能无法转换为图像的有效二进制数据::make()以便能够读取。
您可以尝试将图像的路径传递给make方法。
//If testimage.jpg is located at storage/app/image-storage/492/1
$path = storage_path('app/image-storage/492/1/testimage.jpg');
//if testimage.jpg is located at storage/app/public/image-storage/492/1/, then
//$path = storage_path('app/public/image-storage/492/1/testimage.jpg');
return Image::make($path)->response();或者您可以创建一个新的Illuminate\Http\File实例,然后将其传递给make方法。
//If testimage.jpg is located at storage/app/image-storage/492/1
$path = storage_path('app/image-storage/492/1/testimage.jpg');
//if testimage.jpg is located at storage/app/public/image-storage/492/1/, then
//$path = storage_path('app/public/image-storage/492/1/testimage.jpg');
$file = new \Illuminate\Http\File($path);
Image::make($file)->response();干预映像接受二进制数据或SplFileInfo实例。Illuminate\Http\File扩展了Symfony\Component\HttpFoundation\File\File,后者扩展了\SplFileInfo。
https://stackoverflow.com/questions/72514083
复制相似问题