我有一些代码,可以用于调整jpg、png图像的大小,以下是示例代码。
$image = Image::make("{$filePath}/{$fileName[0]}");
// Get the maximum uploaded image width
$maxWidth = Config::get('constants.max_uploaded_image_width');
// Resize the image
$image->resize($maxWidth, null, function($constraint)
{
// Set an aspect ratio constraint
$constraint->aspectRatio();
// Prevent upsizing
$constraint->upsize();
});
// Save the image
$image->save("{$filePath}/{$fileName[0]}");
这个代码可以很好地处理 jpg
和 png
格式的图像,但当使用 svg
格式时,会返回错误信息“无法读取文件中的图像
”。有什么解决方案吗?