在我的 Laravel 控制器中,我试图获取一串 png 图像数据,然后使用以下命令将其保存为png存储put:$image_string = $request->get('image_string', false);$filename = 'temp_image';if ($image_string) { $resource = imagecreatefromstring($image_string); Log::debug("Storing image"); if ($resource !== false) { Storage::put('public/' . $filename . '.png', imagepng($resource)); } else { Log::error("Failed to get resource from string"); }}如果我只拆分imagecreatefromstring($image_string)和imagepng($resource)部分,则会按预期创建文件。但Storage::put图像中的某处要么损坏,要么丢失,因为虽然存在具有正确文件名和扩展名的图像,但它没有数据,并且在查看时显示为黑框。我需要以不同的方式处理图像存储例程吗?
2 回答

元芳怎么了
TA贡献1798条经验 获得超7个赞
解决方案融合了这两种想法。
$image_string = $request->get('image_string', false);
$filename = 'temp_image';
if ($image_string) {
$resource = Image::make($image_string)->encode('png');
Log::debug("Storing image");
if ($resource !== false) {
Storage::put("public/{$filename}.png", (string) $resource);
} else {
Log::error("Failed to get resource from string");
}
}
- 2 回答
- 0 关注
- 171 浏览
添加回答
举报
0/150
提交
取消