假设我有一个大小为 400 KB 的图像文件。现在我想将它的大小减小到 200 KB!
是否可以使用 laravel 干预?
如果不是我应该遵循哪种方法?
干预图像调整包
最佳答案
上传图片后试试这个功能
function compress($source, $destination, $quality)
{
$info = getimagesize($source);
$image = '';
if ($info['mime'] == 'image/jpeg')
$image = imagecreatefromjpeg($source);
elseif ($info['mime'] == 'image/gif')
$image = imagecreatefromgif($source);
elseif ($info['mime'] == 'image/png')
$image = imagecreatefrompng($source);
imagejpeg($image, $destination, $quality);
return $destination;
}
像这样使用它:
compress(path_to_your_image,same_path_to_reolace_it,quality:10->100)
关于laravel - 如何使用干预减少图像文件的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56969028/