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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -