- Resizing depends on the medium the image is targeted at. Leaving high density displays aside, 500 by 500 is generally sufficient for photos for articles
- If you are going for print, you probably want it to be of higher resolution to meet 300 dpi (dots per inch).
- Generally, the higher the width and height, the bigger the file byte size.
- File formats also play a part, PNGs are bigger, JPGs are usually smaller in file byte size.
- Saving it as JPEG can involve lossy compression, i.e. your compressed image is slightly different from the original
Oct 9, 2020
4
Level 1
Laravel Image Intervention Resizing
Hi,
In one of my blade views of my project, I have an input where the user can upload an image. When storing the image in my project's storage folder (online), I want to resize the image uploaded.
After visiting some forums, I went for the Image intervention package.
This is how I am resizing the image:
use Intervention\Image\Facades\Image;
use Illuminate\Support\Facades\Storage;
Part of the image storing/resizing function:
// Check if an image has been chosen and save to DB
if($request->hasFile('image')) {
$image = $request->file('image');
$path = public_path('../storage/uploads/iotpark/warranty/');
$filename = $id . '_' . $device->sigfox_transceiver_id . '_' . time() . '.' . $image->getClientOriginalExtension();
// Image resizing
$img = Image::make($image->getRealPath());
$img->resize(500, 500, function ($constraint) {
$constraint->aspectRatio();
})->save($path.$filename);
$device->warranty_photo = $filename;
$device->save();
$message = 3;
}
Could someone explain how the resizing function works exactly please?
-
What is the best way to decide what resizing parameters to choose?
-
How does this affect uploaded images of different sizes and ratios?
-
Is there a way to compress the image instead of resizing it?
Thank you in advance for your suggestions :)
Brian
Please or to participate in this conversation.