Image manipulation in Laravel using Spatie/Image

 🖼️ Image Manipulation in Laravel Using Spatie — A Complete Guide (2025)

Image manipulation in Laravel using Spatie/Image

Images are crucial pat of todays applications, whether it's an e-commerce or a simple portfolio website. We often wanted to manipulate images such as cropping, height width adjustments, greyscale etc. before storing them or showing them in the UI. Manually doing these type of manipulation is such an hectic, this is where Spatie comes in the rescue.

Spatie — a popular open-source powerhouse — provides a clean and powerful PHP image manipulation package that works beautifully with Laravel. It’s easy to install, simple to use, and ideal for developers who want flexibility without the hassle.

In this blog, we will be going through:

✔️ What Spatie Image is

✔️ How to install it in Laravel 12

✔️ Multiple real-world examples

✔️ Why it’s useful

✔️ A clean conclusion

Let’s begin! 🚀

🌟 Introduction to Spatie Image

Spatie/Image is a lightweight yet powerful PHP image manipulation library. Spatie provide very simple syntax to work with images easily.

It allows you to:

  • Resize images 📏
  • Crop sections of images ✂️
  • Adjust brightness/contrast ☀️
  • Create thumbnails 🔍
  • Add effects like grayscale 🖤
  • Optimize images for performance ⚡

And what's the best part here?

It integrates smoothly with Laravel with just one command, making image manipulation in your application effortless.

📦 Installing Spatie Image in Laravel

Just use the following command to install spatie image package in your laravel application

composer require spatie/image

Note: Make sure you have required extensions enabled like EXIF and Imagick. Otherwise it might give error.

🧪 Examples of Image Manipulation

🟦 1. Resize an Image

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Spatie\Image\Image;

class HomeController extends Controller
{
    public function showImageManipulation()
    {
        $source = storage_path('app/public/images/building.jpg');
        $destination = storage_path('app/public/images/photo-updated.jpg');

        Image::load($source)
             ->width(600)
            ->height(400)
            ->save($destination);

        $newImage = 'photo-updated.jpg';

        return view('spatie-image', compact('newImage'));
    }
}

Image manipulation in Laravel using Spatie/Image

📌 Use case: Creating different resolution images for mobile and desktop views.

🟩 2. Crop an Image

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Spatie\Image\Image;

class HomeController extends Controller
{
    public function showImageManipulation()
    {
        $source = storage_path('app/public/images/building.jpg');
        $destination = storage_path('app/public/images/photo-updated.jpg');

        Image::load($source)
            ->crop(300, 300)
            ->save($destination);

        $newImage = 'photo-updated.jpg';

        return view('spatie-image', compact('newImage'));
    }
}

Image manipulation in Laravel using Spatie/Image

📌 Use case: Square profile images or thumbnails.

🟨 3. Convert Image to Grayscale

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Spatie\Image\Image;

class HomeController extends Controller
{
    public function showImageManipulation()
    {
        $source = storage_path('app/public/images/building.jpg');
        $destination = storage_path('app/public/images/photo-updated.jpg');

        Image::load($source)
            ->greyscale()
            ->save($destination);

        $newImage = 'photo-updated.jpg';

        return view('spatie-image', compact('newImage'));
    }
}

Image manipulation in Laravel using Spatie/Image

📌 Use case: Stylish UI sections or low-color backgrounds.

🟧 4. Adjust Brightness & Contrast

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Spatie\Image\Image;

class HomeController extends Controller
{
    public function showImageManipulation()
    {
        $source = storage_path('app/public/images/building.jpg');
        $destination = storage_path('app/public/images/photo-updated.jpg');

        Image::load($source)
            ->brightness(20) // increase brightness
            ->contrast(-10)
            ->save($destination);

        $newImage = 'photo-updated.jpg';

        return view('spatie-image', compact('newImage'));
    }
}

Image manipulation in Laravel using Spatie/Image

📌 Use case: Enhancing raw photos uploaded by users.

🟥 5. Blur an Image

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Spatie\Image\Image;

class HomeController extends Controller
{
    public function showImageManipulation()
    {
        $source = storage_path('app/public/images/building.jpg');
        $destination = storage_path('app/public/images/photo-updated.jpg');

        Image::load($source)
            ->blur(30)
            ->save($destination);

        $newImage = 'photo-updated.jpg';

        return view('spatie-image', compact('newImage'));
    }
}

Image manipulation in Laravel using Spatie/Image

📌 Use case: Blurred backgrounds for headers or hero sections.

🟪 6. Optimize Image for Web

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Spatie\Image\Image;

class HomeController extends Controller
{
    public function showImageManipulation()
    {
        $source = storage_path('app/public/images/building.jpg');
        $destination = storage_path('app/public/images/photo-updated.jpg');

        Image::load($source)
            ->quality(10)
            ->save($destination);

        $newImage = 'photo-updated.jpg';

        return view('spatie-image', compact('newImage'));
    }
}

Image manipulation in Laravel using Spatie/Image

📌 Use case: Speed up your website loading time.

🟫 7. Combine Multiple Transformations

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Spatie\Image\Image;

class HomeController extends Controller
{
    public function showImageManipulation()
    {
        $source = storage_path('app/public/images/building.jpg');
        $destination = storage_path('app/public/images/photo-updated.jpg');

        Image::load($source)
            ->width(800)
            ->height(600)
            ->crop(600, 400)
            ->greyscale()
            ->brightness(-5)
            ->save($destination);

        $newImage = 'photo-updated.jpg';

        return view('spatie-image', compact('newImage'));
    }
}

Image manipulation in Laravel using Spatie/Image

📌 Use case: Creating custom processed images automatically after upload.

🌈 How Spatie Image Helps in Real Projects

Spatie Image isn’t just for fun — it solves real-world problems and business need. Here's why it's incredibly useful:

💡 1. Automatic Image Processing

💨 2. Improves Page Speed

🎯 3. Better User Experience

🔐 4. Works Without External Services

🧩 5. Highly Customizable

⚙️ 6. Perfect for E-commerce, Blogs, and Admin Panels

Handy for generating:

  • product thumbnails
  • social media preview images
  • blog featured images
  • user profile images

🏁 Conclusion

Spatie Image is a simple yet powerful tool that makes image manipulation in Laravel incredibly smooth. From resizing and cropping to applying grayscale or optimization, everything can be done with clean, expressive code.

Start using it today and give your Laravel application the power it deserves! 💪🔥

Thank you for reading this article 😊

For any query do not hesitate to comment 💬


Previous Post Next Post

Contact Form