Search code examples
phpimagelaravelimage-compression

Is laravel image intervention a good way to compress user uploaded images?


I was checking out this laravel library to compress user uploaded images.http://image.intervention.io/

I was wondering if this is a good idea for user uploaded images (for profilepictures)? What if the user uploads a picture with a size of 1400x600 and it will be resized to 200x200? Will it be a stretched out image?


Solution

  • Yes, it will be stretched. You want to try fit() method:

    Combine cropping and resizing to format image in a smart way. The method will find the best fitting aspect ratio of your given width and height on the current image automatically, cut it out and resize it to the given dimension.

    // crop the best fitting 1:1 ratio (200x200) and resize to 200x200 pixel
    $img->fit(200);