Convert Figma logo to code with AI

Intervention logoimage

PHP Image Processing

13,849
1,498
13,849
27

Top Related Projects

2,547

Wonderfully easy on-demand image manipulation library with an HTTP based API.

1,236

Manipulate images with an expressive API

4,415

PHP Object Oriented image manipulation library

1,003

A PHP library to handle images

🌄 Perceptual image hashing for PHP

Quick Overview

Intervention/image is a powerful PHP image handling and manipulation library. It provides an easy-to-use interface for opening, manipulating, and saving images, supporting various formats and offering a wide range of image processing functions.

Pros

  • Simple and intuitive API for image manipulation
  • Supports multiple image formats (JPEG, PNG, GIF, BMP, etc.)
  • Extensive set of image processing functions (resize, crop, filter, etc.)
  • Actively maintained with regular updates

Cons

  • Requires GD library or Imagick PHP extension
  • Performance may be slower compared to native image processing libraries
  • Limited support for advanced image processing techniques
  • Some functions may produce inconsistent results across different PHP versions or server configurations

Code Examples

Opening an image and resizing it:

use Intervention\Image\ImageManagerStatic as Image;

$image = Image::make('path/to/image.jpg');
$image->resize(300, 200);
$image->save('path/to/resized_image.jpg');

Applying filters and effects:

use Intervention\Image\ImageManagerStatic as Image;

$image = Image::make('path/to/image.jpg');
$image->greyscale();
$image->brightness(50);
$image->blur(15);
$image->save('path/to/filtered_image.jpg');

Creating a thumbnail with custom dimensions:

use Intervention\Image\ImageManagerStatic as Image;

$image = Image::make('path/to/image.jpg');
$image->fit(100, 100);
$image->save('path/to/thumbnail.jpg');

Getting Started

  1. Install the library using Composer:
composer require intervention/image
  1. Use the library in your PHP code:
<?php

require 'vendor/autoload.php';

use Intervention\Image\ImageManagerStatic as Image;

// Open an image file
$image = Image::make('path/to/image.jpg');

// Perform manipulations
$image->resize(300, 200);
$image->greyscale();

// Save the modified image
$image->save('path/to/modified_image.jpg');

This quick start guide demonstrates how to install the library, open an image, perform basic manipulations, and save the result.

Competitor Comparisons

2,547

Wonderfully easy on-demand image manipulation library with an HTTP based API.

Pros of Glide

  • Offers a URL-based API for image manipulation, making it easy to integrate with web applications
  • Provides secure image processing with features like signing URLs to prevent unauthorized manipulations
  • Includes built-in caching mechanisms for improved performance

Cons of Glide

  • Less extensive manipulation options compared to Intervention/image
  • Primarily focused on URL-based operations, which may not be ideal for all use cases
  • Steeper learning curve for developers accustomed to more traditional image processing libraries

Code Comparison

Glide:

$server = League\Glide\ServerFactory::create([
    'source' => 'path/to/source/folder',
    'cache' => 'path/to/cache/folder',
]);
$server->outputImage('image.jpg', ['w' => 300, 'h' => 200]);

Intervention/image:

$img = Image::make('public/foo.jpg');
$img->resize(300, 200);
$img->save('public/bar.jpg');

Both libraries offer image manipulation capabilities, but Glide focuses on URL-based operations and secure processing, while Intervention/image provides a more traditional approach with a wider range of manipulation options. Glide's URL-based API can be advantageous for web applications, while Intervention/image's flexibility may be preferred for more complex image processing tasks.

1,236

Manipulate images with an expressive API

Pros of spatie/image

  • Lightweight and focused on modern PHP practices
  • Seamless integration with Laravel framework
  • Supports image manipulation via Glide server

Cons of spatie/image

  • Limited built-in manipulation methods compared to Intervention/image
  • Less extensive documentation and community support
  • Primarily designed for Laravel, potentially less flexible for other frameworks

Code Comparison

spatie/image:

$image = Image::load('image.jpg')
    ->width(300)
    ->height(200)
    ->save();

Intervention/image:

$img = Image::make('image.jpg')
    ->resize(300, 200)
    ->save();

Both libraries offer similar basic functionality for image manipulation, but Intervention/image provides more extensive options and methods out of the box. spatie/image is more focused on integration with Laravel and leverages Glide for manipulations, while Intervention/image is a standalone library with broader compatibility across different PHP frameworks.

spatie/image is ideal for Laravel projects requiring simple image manipulations, while Intervention/image is better suited for complex image processing needs or projects using various PHP frameworks.

4,415

PHP Object Oriented image manipulation library

Pros of Imagine

  • More extensive image manipulation features, including advanced filters and effects
  • Better support for various image formats, including TIFF and WebP
  • More actively maintained with frequent updates and bug fixes

Cons of Imagine

  • Steeper learning curve due to more complex API
  • Slower performance for basic image operations compared to Image
  • Larger library size, which may impact project load times

Code Comparison

Image (Intervention):

$img = Image::make('public/foo.jpg');
$img->resize(300, 200);
$img->save('public/bar.jpg');

Imagine:

$imagine = new Imagine\Gd\Imagine();
$image = $imagine->open('public/foo.jpg');
$image->resize(new Box(300, 200));
$image->save('public/bar.jpg');

Both libraries offer similar basic functionality, but Imagine's syntax is slightly more verbose. Image provides a more fluent interface, while Imagine offers more granular control over image operations.

1,003

A PHP library to handle images

Pros of Image

  • Lightweight and simple to use
  • Supports chaining methods for fluent image manipulation
  • Includes built-in caching mechanism for improved performance

Cons of Image

  • Less extensive feature set compared to its counterpart
  • Limited documentation and community support
  • Fewer image processing options available out-of-the-box

Code Comparison

Image:

$image = new Image();
$image->open('image.jpg')
      ->resize(100, 100)
      ->save('thumbnail.jpg');

Intervention:

$image = Image::make('image.jpg');
$image->resize(100, 100);
$image->save('thumbnail.jpg');

Both libraries offer similar syntax for basic image manipulation tasks. Image uses method chaining, while Intervention uses separate method calls. The main difference lies in the initialization of the image object and the available methods for more advanced operations.

Image is more suitable for simple image processing tasks and projects requiring a lightweight solution. Intervention, on the other hand, provides a more comprehensive set of features and better documentation, making it ideal for complex image manipulation needs and larger projects.

🌄 Perceptual image hashing for PHP

Pros of imagehash

  • Specialized in perceptual image hashing for similarity comparison
  • Lightweight and focused on a specific task
  • Supports multiple hashing algorithms (average, perceptual, difference, wavelet)

Cons of imagehash

  • Limited to image hashing functionality
  • Fewer image manipulation features compared to Image
  • Less active development and smaller community

Code Comparison

imagehash:

use Jenssegers\ImageHash\ImageHash;

$hasher = new ImageHash();
$hash = $hasher->hash('path/to/image.jpg');
$similarity = $hash->compare($otherHash);

Image:

use Intervention\Image\ImageManagerStatic as Image;

$image = Image::make('path/to/image.jpg');
$image->resize(300, 200);
$image->save('path/to/modified_image.jpg');

Summary

imagehash is a specialized library for perceptual image hashing, ideal for comparing image similarity. It's lightweight and supports multiple hashing algorithms. However, it lacks the extensive image manipulation features offered by Image.

Image, on the other hand, is a more comprehensive image handling library with a wide range of manipulation functions. It's better suited for tasks like resizing, cropping, and applying filters to images. Image has a larger community and more active development, making it a more versatile choice for general image processing needs.

Choose imagehash for specific image comparison tasks, and Image for broader image manipulation requirements.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Intervention Image

PHP Image Processing

Latest Version Build Status Monthly Downloads Support me on Ko-fi

Intervention Image is a PHP image processing library that provides a simple and expressive way to create, edit, and compose images. It features a unified API for the two most popular image manipulation extensions. You can choose between the GD library or Imagick as the base layer for all operations.

  • Simple interface for common image editing tasks
  • Interchangeable driver architecture
  • Support for animated images
  • Framework-agnostic
  • PSR-12 compliant

Installation

You can easily install this library using Composer. Just request the package with the following command:

composer require intervention/image

Getting Started

Learn the basics on how to use Intervention Image and more with the official documentation.

Code Examples

use Intervention\Image\ImageManager;

// create image manager with desired driver
$manager = new ImageManager(
    new Intervention\Image\Drivers\Gd\Driver()
);

// open an image file
$image = $manager->read('images/example.gif');

// resize image instance
$image->resize(height: 300);

// insert a watermark
$image->place('images/watermark.png');

// encode edited image
$encoded = $image->toJpg();

// save encoded image
$encoded->save('images/example.jpg');

Requirements

  • PHP >= 8.1

Supported Image Libraries

  • GD Library
  • Imagick PHP extension

Security

If you discover any security related issues, please email oliver@intervention.io directly.

Authors

This library is developed and maintained by Oliver Vogel

Thanks to the community of contributors who have helped to improve this project.

License

Intervention Image is licensed under the MIT License.