Laravel干预 - 无法从给定的二进制数据中启动

发布于 2025-02-05 05:22:45 字数 552 浏览 3 评论 0原文

我正在我的一个项目中使用“干预/图像”:“^2.5”。除了要检索图像的代码的一部分外,它的运行良好。

我一直无法从给定的二进制数据错误中启动错误,但我无法弄清楚原因。

该文件存在,但我无法弄清楚。

我的代码如下;

$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'),
],

I am using "intervention/image": "^2.5" in one of my projects. It is working well except for one part of the code where im retrieving an image.

I keep getting a Unable to init from given binary data error and i cant figure out why.

The file exists but i cant figure it out.

My code is as follows;

$path = '/image-storage/492/1/testimage.jpg';
$file = Storage::get($path);
ob_end_clean();

return Image::make($file)->response();

Below is my filesystem.php config for local

'local' => [
    'driver' => 'local',
    'root' => storage_path('app'),
],

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

榕城若虚 2025-02-12 05:22:46

存储:: get($ path)返回文件内容作为字符串,可能不会将其施放为 image :: 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实例,然后将其传递到 方法

//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 实例。 照明\ http \ file扩展symfony \ component \ httpfoundation \ httpfoundation \ file \ file \ file \ file \ splfileinfo

“干预图像” - 阅读图像

Storage::get($path) returns file contents as a string which may not be cast to valid binary data for Image::make() to be able to read.

You can try by passing the path to the image to the make method

//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();

OR you can create a new Illuminate\Http\File instance and then pass it to the make method

//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();

Intervention image accepts binary data or SplFileInfo instance. Illuminate\Http\File extends Symfony\Component\HttpFoundation\File\File which extends \SplFileInfo.

Intervention Image - Reading Images

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文