我正在制作电子商务门户网站。我正尝试以不同的分辨率上传图像,这是完全正常的。Laravel 5 - 上传后的模糊图像 - 干预
但问题是,如果我在浏览器上传后查看它,我会看到模糊的图像,这不是我想要的。我希望在上传之后,图像应该清晰可见,不应该模糊。
下面是它的控制器方法:
public function store(AddProductRequest $request) {
if(\Auth::guest()) {
return redirect('/admin');
}
$imageType = [
'thumbnail' => [
'height' => 75,
'width' => 75
],
'product' => [
'height' => 450,
'width' => 450
],
'cart' => [
'height' => 200,
'width' => 200
]
];
if ($request->file('image_file')) {
$fileName = $request->file('image_file')->getClientOriginalName();
$fileName = explode('.', $fileName);
$image = \Image::make($request->file('image_file'));
$path = public_path('images/uploads/');
foreach ($imageType as $key => $value) {
if ($key == 'thumbnail') {
$image->resize($value['width'], $value['height'], function($constraint) {
$constraint->aspectRatio();
});
$image->save($path.$fileName[0]."-thumbnail-". $value['width'] ."-".$value['height'] .".jpg", 100);
} elseif ($key == 'product') {
$image->resize($value['width'], $value['height'], function($constraint) {
$constraint->aspectRatio();
});
$image->save($path.$fileName[0]."-product-". $value['width'] ."-".$value['height'] .".jpg", 100);
} elseif ($key == 'cart') {
$image->resize($value['width'], $value['height'], function($constraint) {
$constraint->aspectRatio();
});
$image->save($path.$fileName[0]."-cart-". $value['width'] ."-".$value['height'] .".jpg", 100);
}
}
}
$product = Product::create($request->all());
$product->tags()->attach($request->input('tags'));
\Session::flash('product_added', 'Product has been successfully added in the database.');
return redirect('admin/products');
}
如何避免上载后显示模糊图像?
请帮助我。提前致谢。
任何人都可以帮我吗? –
原始图像的大小是多少?调整大小的图像的大小是多少? –
图像的原始大小是1000x1000。调整后的图像大小是数组中给出的大小。 –