我正在使用Intervention Image上传单个图像的两个版本(小和大)以在不同页面上显示。
用户始终上传 1000 x 1000 像素的图像,原始图像用于单个产品的产品页面,较小的版本用于“所有产品”页面。
这工作得很好,只是缩小的图像质量很差。它是像素化的。
我正在使用 Laravel 4.2。我的php版本是5.5.11。我正在本地主机上使用 Xampp 进行开发。我看过this question我很确定 GD 已安装。
是因为GD不如imagick吗?因为我似乎一生都无法安装那个东西......
编辑:这就是问题所在!我终于设法让 imagick 工作并将其更改为驱动程序。高质量的图像。
这是我的路线,尽管我不认为这就是问题所在:
$file = Input::file('photo');
$fileName = Input::get('name').'.'.$file->getClientOriginalExtension();
$fileName= str_replace(' ', '_', $fileName);
$destinationPath = 'productphotos/';
// upload new image
Image::make($file->getRealPath())
// original
->save($destinationPath.$fileName)
// resize
->resize(300, 300) // set true if you want proportional image resize
->save($destinationPath.'resize'.$fileName, 100);
$aDetails = Input::all();
$aDetails["photo"] = $fileName;
$aDetails["smallphoto"] = 'resize'.$fileName;
Product::create($aDetails);
return Redirect::to("products/".Input::get("product_id"));
您可以看到stock test(原始尺寸1000x1000)和testresize(300x300)之间的差异。它们都以 218x218 显示。
最佳答案
我终于设法让 imagick 工作并将其更改为驱动程序。高质量的图像。 GD驱动是问题所在,解决办法是换成imagick驱动。 干杯!
关于php - 干预图像会降低调整大小时的图像质量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29313811/