在我的Laravel web应用中,我使用Intervention Image库。我保存了上传的图像的三个版本:
Intervention 的驱动程序在配置中设置为
'original'
,'500_auto'
和一个自定义大小的图像。$image = Image::make(Input::file('file');
// Save the orignal image
$image->save($folder . 'original.' . $extension);
// Save 500_auto image
$image->resize(500, null, function($constraint) {
$constraint->aspectRatio();
});
$image->save($folder . '500_auto.' . $extension, 100);
// Check if size is set
if (isset($config->images->width) && isset($config->images->height)) {
// Assign values
$width = $config->images->width;
$height = $config->images->height;
// Create the custom thumb
$image->resize($width, $height, function($constraint) {
$constraint->aspectRatio();
});
$image->save($folder . $width . '_' . $height . '.' . $extension, 100);
}
Intervention 的驱动程序在配置中设置为
'gd'
:'driver' => 'gd'
这是我正在上传的图片:original.jpg
这是使用配置设置精确匹配原始尺寸(1800 x 586)的自定义缩略图结果:1800_586.jpg
如您所见,第二张图像在调整大小后存在大量的质量损失。我该如何解决这个问题?
Image :: make()
是一个好方法。这就是导致调整大小函数中图像模糊的原因。 - Jay Pandya