Reputation: 13
I need upload images with 3 different thumbnails sizes.
For example I upload image and now I get one thumbnail (48x48px), and I want to have 3 sizes: 100x100px, 300x300px, 600x600px.
How can I do this? Help me please.
Upvotes: 0
Views: 1143
Reputation: 2683
You can use package for that, this is best package you can use for that Image intervention
You can use this code for resizing image after uploading.
// open an image file
$img = Image::make('public/original.jpg');
// now you are able to resize the instance
$img->resize(48,48);
// finally we save the image as a new file
$img->save('public/resized.jpg');
you can get installation setups for Laravel here
Also please refer documentation here.
Please refer this below code which I'm using to resize images.
// Upload image to Disk
$pic = $request->file('image');
$name = $pic->getClientOriginalName();
$extension = $pic->getClientOriginalExtension();
$encrypted_name = md5(uniqid().time()).".".$extension; //Generate Unique name image
$pic->move("Path/to/Uploads",$encrypted_name);
// Read that image and resize that image.
$Image = "Path/to/Uploads".$image_name;
$img = \Image::make($Image)->resize(48,48);
$img->save('new_image_name');
Upvotes: 5