我正在升级一个从Laravel 5到5.1的项目。需要更新的一个包是League\Flysystem。
我使用Intervention\Image来调整图像的大小,然后使用Flysystem将其保存到S3中。下面的代码使用5.0 -
// Album ID
$id = $request->input('id');
// Filename for this photo
$filename = str_random() . ".jpg";
// Get the storage disk
$disk = Storage::disk('s3');
// Resize the photo
$image = Image::make($request->file('photo'));
$image->orientate();
$image->resize(1024, 748, function ($constraint) {
$constraint->aspectRatio();
});
$image->encode('jpg');
// Save the photo to the disk
$disk->put("img/album/$id/$filename", $image);但是现在我收到了以下错误:fstat() expects parameter 1 to be resource, object given,在league\flysystem\src\Util.php中抛出,第250行。
我用的是"intervention/image": "~2.1","league/flysystem-aws-s3-v3" : "~1.0",
有什么原因吗?
发布于 2015-06-09 17:35:51
在您的$image对象上的某个类型转换用它做字符串之前,您可能是幸运的,我想简单地将最后一行更改为
$disk->put("img/album/$id/$filename", $image->__toString());将修复这个问题,而且安全一些,因为put方法只接受字符串(并将php资源的实现视为wekk)。
从长远来看,这将使您与更改保持兼容。
发布于 2015-06-13 16:12:35
更好的方法是键入强制转换编码的输出:
http://image.intervention.io/api/encode
$image->encode('jpg');
$disk->put("img/album/$id/$filename", (string) $image);发布于 2018-12-05 06:41:56
我有"intervention/image": "^2.4",版
__toString()不适合我,文件被破坏了.我做了->stream()->getContents()。
https://stackoverflow.com/questions/30738520
复制相似问题