In my Laravel controller I'm attempting to take a string of image data, convert it to a png then save it to storage using 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");
}
}
If I break out just the imagecreatefromstring($image_string) and imagepng($resource) parts, the file is created as expected. But somewhere in the Storage::put the image is either corrupted or lost, because while an image with the right filename and extension exists, it has no data and appears as a black box when viewed.
Is there a different way I need to handle the image store routine?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire