mirror of
https://github.com/sakaljurgis/actions-api.git
synced 2026-07-08 22:07:40 +00:00
initial commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Image;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ImageService
|
||||
{
|
||||
/**
|
||||
* @param string $base64ImageData
|
||||
* @param string $mimeType
|
||||
* @return array ['url', 'id']
|
||||
*/
|
||||
public function saveImage(string $base64ImageData, string $mimeType): array
|
||||
{
|
||||
$imageId = uniqid();
|
||||
$imageData = base64_decode($base64ImageData);
|
||||
$ext = explode('/', $mimeType)[1];
|
||||
|
||||
Storage::put('public/images/' . $imageId . '.' . $ext , $imageData);
|
||||
$relativePath = Storage::url('public/images/' . $imageId . '.png');
|
||||
|
||||
return [
|
||||
'url' => asset($relativePath),
|
||||
'id' => $imageId,
|
||||
// todo - size, width, height, thumb, etc
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user