February 4, 2015 11:53 am

Image Upload and Resize using Image Intervention in Laravel

In this tutorial we will cover one of the most used feature Image Upload functionality in any web application over Internet using Laravel 4 and Image Intervention package. Let’s see how we can do Image upload and resizing by allowing people to upload images to our website via a From.

Image Upload and Resize using Image Intervention in Laravel

Image Upload Form

Let’s create a view which will contain our upload form with name form.blade.php in app/views/  directory.

This Image upload form was built by using laravel 4 Form helpers to generate a simple form with image upload input type by setting ‘files’ => true parameter.
When we accessed the view using our route url http://domain.com/.

Image Intervention in Laravel

Post Action in Laravel 4 Route or Controller

Let’s dive into the post action code, but before that let’s check whether the image was uploaded or not to do operations on that image file.

  • Check if image was uploaded or not
  • Let’s find out the file and move it onto our server
  • Using the path of the image on our server, open and resize our Image
  • Save the resize image

Let’s implement these steps either in our Route or Controller

The above code covers first 2 steps. We check if a image file named avatar is present or not. If so we move that image into the uploads directory keeping the name it was uploaded with.

Adding Intervention for Image Resizing

To get started with Intervention, add it to our composer.json file.

And run composer update from the root of our project

Next we have to add providers and array aliases names for Intervention package in app/config/app.php file

Resizing Images

With Intervention package installed, we simply need to call the methods to resize image and save it into our server.

That’s it we have resized the image and saved the image at public/uploads directory. We can add watermark to the image also using another method called insert().

There are lot of other methods we can try from Image Intervention package please check official documentation.


Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.

Tutorial Categories:
  • Great!
    Upload image, resize default code php.
    You customizing auto rezie. Thank

  • tanveer

    Can you help me in laravel php problems like upload images and session