我有这个功能可以通过 Laravel 中的 api 上传图像:
private function handleImage($image)
{
$exploded = explode(',', $image);
$decoded = base64_decode($exploded[1]);
if (Str::contains($exploded[0], 'jpeg')) {
$extension = 'jpg';
} else {
$extension = 'png';
}
$fileName = Str::random() . '.' . $extension;
$path = public_path() . '/images/products/' . $fileName;
$file = file_put_contents($path, $decoded);
$image = '/images/products/' . $fileName;
return $image;
}
如何在上传之前将图像调整为最大边长 500 像素的大小?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号