Laravel Resize Image Before Upload Example

Today, We want to share with you Laravel Resize Image Before Upload Example.In this post we will show you laravel 7/6 image intervention example, hear for resize image in laravel using intervention image library we will give you demo and example for implement.In this post, we will learn about resize image intervention laravel 7/6 with an example image upload in laravel.

Laravel Resize Image Before Upload Example

There are the Following The simple About PHP Laravel 5 Intervention image upload and resize tutorial Full Information With upload image laravel Example and source code.

As I will cover this Post with live Working example to develop laravel 6/7 resizes image before upload, so the Smooth image upload and resizes in laravel is used for this laravel upload image example is following below.

Phase 1: Install Laravel 7/6

Laravel 6 application setup upload image laravel then we have to get fresh laravel 6 application

composer create-project --prefer-dist laravel/laravel blog

Phase 2: Install Intervention Image Package

install intervention/image for resizes image

composer require intervention/image

config/app.php

return [
    ......
    $provides => [
        ......
        ......,
        'Intervention\Image\ImageServiceProvider'
    ],
    $aliases => [
        .....
        .....,

        'Image' => 'Intervention\Image\Facades\Image'
    ]
]

Phase 3: Create Routes

routes/web.php

Route::get('flexifyLiveImg', 'flexifyImgController@flexifyLiveImg');
Route::post('liveFlexifyImg', 'flexifyImgController@liveFlexifyImg')->name('liveFlexifyImg');

Phase 4: Create Controller File

create new flexifyImgController for image uploading and resizeing image

php artisan make:controller flexifyImgController

app/Http/Controllers/flexifyImgController.php

validate($request, [
            'title' => 'required',
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ]);
  
        $image = $request->file('image');
        $input['imagename'] = time().'.'.$image->extension();
     
        $destinationPath = public_path('/thumbnail');
        $img = Image::make($image->path());
        $img->resize(100, 100, function ($constraint) {
            $constraint->aspectRatio();
        })->save($destinationPath.'/'.$input['imagename']);
   
        $destinationPath = public_path('/images');
        $image->move($destinationPath, $input['imagename']);
   
        return back()
            ->with('success','Image Upload successful')
            ->with('flexifyImgNm',$input['imagename']);
    }
   
}

Phase 5: View File and Create Upload directory

resources/views/flexifyLiveImg.blade.php

@extends('layouts.app')
   
@section('content')

Resize Image Uploading Demo

@if (count($errors) > 0)
Whoops! There were some problems with your input.

    @foreach ($errors->all() as $error)
  • {{ $error }}
  • @endforeach
@endif @if ($message = Session::get('success'))
{{ $message }}
Original Image:
laravel resize image
Convert Thumbnail Image:
laravel resize image
@endif {!! Form::open(array('route' => 'liveFlexifyImg','enctype' => 'multipart/form-data')) !!}

{!! Form::text('title', null,array('class' => 'form-control dsp','placeholder'=>'Add Title')) !!}

{!! Form::file('image', array('class' => 'image')) !!}

{!! Form::close() !!}
@endsection
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about laravel image converter.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment