在我的 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图像中的某处要么损坏,要么丢失,因为虽然存在具有正确文件名和扩展名的图像,但它没有数据,并且在查看时显示为黑框。
我需要以不同的方式处理图像存储例程吗?
元芳怎么了