0

I'm studying photo upload script. Here is my code below this works fine.

I would like to add resizing photo function.

I would like to Keep same RATIO (height and width) And

I would like to change it around 2.8M (1920 x 1440) size or make it all photo will be max width size is 1920.

Could you teach me how to add this fucntion to my code please?

UPDATE(I add Dear Dilip Hirapara code )

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\ImageGallery;
use DB;
use Intervention\Image\ImageManagerStatic as Image;

 public function upload(Request $request)
    {
    $this->validate($request, [
        'image' => 'required|mimes:jpeg,jpg|max:90480'
    ]);

    $input['image'] = time().'.'.$request->image->getClientOriginalExtension();
    $request->image->move(public_path('images'), $input['image']);


    if($request->hasFile('image')) {

$image       = $request->file('image');
$filename    = $image->getClientOriginalName();

$image_resize = Image::make($image->getRealPath());              
$image_resize->resize(300, 300);
$image_resize->save(public_path('images/ServiceImages/' .$filename));

}
$request->image->move(public_path('images'), $input['image']);

ImageGallery::create($input);

    return back()
        ->with('sucess','sucess');
}

1 Answer 1

1

Install the intervention/image by using this command.

composer require intervention/image

Check the official document for installation

check this link to resize image.

if($request->hasFile('image')) {

    $image       = $request->file('image');
    $filename    = $image->getClientOriginalName();

    $image_resize = Image::make($image->getRealPath());              
    $image_resize->resize(300, 300);
    $image_resize->save(public_path('images/ServiceImages/' .$filename));

}
$request->image->move(public_path('images'), $input['image']);

enter image description here

Sign up to request clarification or add additional context in comments.

10 Comments

Thank you very much for code. I really apreciate. May I ask one things? I have this error Intervention\Image\Exception\NotReadableException Unable to find file (/var/tmp/phpvnQjg0 . I searched at web... Is it temp file problem?
The problem is when you upload any file first it goes to tmp folder..once that file moved or if we use move action the tmp file automatically deleted. that's why right now you're unable to find it.
Add your move functionality after this code. $file->move($path, $filename);
Dear @Dilip Hirapara Now I understand the temp meaning Thank you very much again. Well actually I add your code but I still got same error. I update my current code. Could you take a look it? And Could you teach me what is cause my writing?
The move function should be in last..check my edited answer. $file->move($path, $filename); remove this line..and add your move function.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.