Intervention image aspect ratio -
i want resize images through intervention image functionality in laravel 4, keep aspect ratio of image, code looks like:
$image_make = image::make($main_picture->getrealpath())->fit('245', '245', function($constraint) { $constraint->aspectratio(); })->save('images/articles/'.$gender.'/thumbnails/245x245/'.$picture_name);
problem doesn't keep aspect ratio of image, thanks.
if need resize within constraints should use resize
not fit
. if need center image inside constraints, should create new canvas
, insert resized image within that:
// generate image transparent background // if need have background can pass third parameter (e.g: '#000000') $canvas = image::canvas(245, 245); $image = image::make($main_picture->getrealpath())->resize(245, 245, function($constraint) { $constraint->aspectratio(); }); $canvas->insert($image, 'center'); $canvas->save('images/articles/'.$gender.'/thumbnails/245x245/'.$picture_name);
Comments
Post a Comment