我正在制作一个电子商务门户网站。我正在尝试以不同的分辨率上传图像,这完全正常。
但问题是,如果我在上传后在浏览器中查看它,我会看到模糊的图像,这不是我想要的。我希望在上传后,图像应该清晰可见并且不应该模糊。
这是它的控制器方法:
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');
}
上传后如何避免显示模糊的图像?
请帮助我。提前致谢。