Top Related Projects
Wonderfully easy on-demand image manipulation library with an HTTP based API.
PHP Image Processing
PHP Object Oriented image manipulation library
A PHP class that makes working with images and GD as simple as possible.
A PHP library to handle images
Quick Overview
Spatie/image is a PHP package that provides an easy-to-use, fluent interface for image manipulation. It serves as a wrapper around Intervention Image, offering a more intuitive API for common image operations such as resizing, cropping, and applying filters.
Pros
- Simple and expressive API for image manipulation
- Built on top of the robust Intervention Image library
- Supports various image formats (JPEG, PNG, GIF, WEBP)
- Chainable methods for complex image transformations
Cons
- Requires GD Library or Imagick PHP extension
- Limited advanced features compared to professional image editing software
- Performance may be slower for large-scale image processing tasks
- Dependency on Intervention Image may introduce potential conflicts in some projects
Code Examples
- Resizing an image:
use Spatie\Image\Image;
Image::load('input.jpg')
->width(300)
->height(200)
->save('output.jpg');
- Applying multiple transformations:
use Spatie\Image\Image;
Image::load('input.jpg')
->crop(Manipulations::CROP_CENTER, 800, 600)
->blur(50)
->brightness(30)
->save('output.jpg');
- Converting image format:
use Spatie\Image\Image;
Image::load('input.jpg')
->format(Manipulations::FORMAT_WEBP)
->quality(90)
->save('output.webp');
Getting Started
- Install the package via Composer:
composer require spatie/image
- Basic usage example:
use Spatie\Image\Image;
use Spatie\Image\Manipulations;
Image::load('input.jpg')
->crop(Manipulations::CROP_CENTER, 400, 400)
->greyscale()
->save('output.jpg');
This example loads an image, crops it to a 400x400 square from the center, converts it to greyscale, and saves the result.
Competitor Comparisons
Wonderfully easy on-demand image manipulation library with an HTTP based API.
Pros of Glide
- More extensive image manipulation options, including advanced filters and effects
- Built-in HTTP-based API for easy integration with web applications
- Supports multiple storage backends (local, Amazon S3, etc.)
Cons of Glide
- Steeper learning curve due to more complex API
- Requires more setup and configuration for basic usage
- Larger footprint and potentially slower for simple operations
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,
'fit' => 'crop'
]);
Image:
use Spatie\Image\Image;
Image::load('image.jpg')
->width(300)
->height(200)
->crop(Manipulations::CROP_CENTER)
->save('output.jpg');
Both libraries offer powerful image manipulation capabilities, but Glide provides more advanced features and flexibility at the cost of complexity. Image focuses on simplicity and ease of use for common operations. The choice between them depends on the specific requirements of your project and the level of control you need over image processing.
PHP Image Processing
Pros of Intervention/image
- More extensive feature set, including advanced image manipulation capabilities
- Larger community and ecosystem, with more third-party extensions available
- Better documentation and examples for various use cases
Cons of Intervention/image
- Heavier and potentially slower for simple image operations
- More complex API, which may be overkill for basic image handling tasks
- Requires GD library or Imagick extension, which may not be available on all servers
Code Comparison
Intervention/image:
$image = Image::make('public/foo.jpg')
->resize(300, 200)
->greyscale()
->save('public/bar.jpg', 80);
spatie/image:
Image::load('public/foo.jpg')
->width(300)
->height(200)
->greyscale()
->save('public/bar.jpg', 80);
Both libraries offer similar functionality for basic image manipulation, but Intervention/image provides more advanced features and flexibility at the cost of a slightly more verbose API. spatie/image focuses on simplicity and ease of use, making it a good choice for projects with straightforward image processing needs.
PHP Object Oriented image manipulation library
Pros of Imagine
- More comprehensive image manipulation library with a wider range of features
- Supports multiple image processing libraries (GD, Imagick, Gmagick)
- Longer development history and larger community
Cons of Imagine
- Steeper learning curve due to more complex API
- Heavier library with more dependencies
- May be overkill for simple image manipulation tasks
Code Comparison
Imagine:
$imagine = new Imagine\Gd\Imagine();
$image = $imagine->open('path/to/image.jpg');
$image->resize(new Imagine\Image\Box(300, 200))
->save('path/to/resized.jpg');
Image:
$image = Image::load('path/to/image.jpg');
$image->width(300)
->height(200)
->save('path/to/resized.jpg');
Summary
Imagine is a more feature-rich and flexible image manipulation library, supporting multiple processing backends and offering a wide range of operations. It's ideal for complex image processing tasks but may be overwhelming for simpler use cases.
Image, on the other hand, provides a more straightforward and lightweight approach to image manipulation. It's easier to use for basic tasks but may lack some advanced features found in Imagine.
The choice between the two depends on the specific requirements of your project, the complexity of image manipulations needed, and your preference for API simplicity versus feature completeness.
A PHP class that makes working with images and GD as simple as possible.
Pros of SimpleImage
- Lightweight and easy to use, with a simple API for basic image manipulation tasks
- Supports a wide range of image formats, including WebP
- No external dependencies, making it easier to integrate into projects
Cons of SimpleImage
- Limited advanced features compared to Image
- Less actively maintained, with fewer recent updates
- Lacks some modern PHP features and optimizations
Code Comparison
SimpleImage:
$image = new \claviska\SimpleImage();
$image
->fromFile('image.jpg')
->resize(300, 200)
->toFile('resized.jpg', 'image/jpeg', 90);
Image:
$image = Image::load('image.jpg');
$image
->width(300)
->height(200)
->save('resized.jpg', 90);
Both libraries offer straightforward APIs for basic image manipulation tasks. SimpleImage provides a more compact syntax, while Image offers a more expressive and chainable approach. Image also provides more advanced features and optimizations, making it suitable for more complex image processing requirements. However, SimpleImage's simplicity and lack of dependencies may be advantageous for smaller projects or those with limited image manipulation needs.
A PHP library to handle images
Pros of Image
- More comprehensive image manipulation features, including advanced filters and effects
- Supports a wider range of image formats, including GIF and BMP
- Includes built-in caching mechanism for improved performance
Cons of Image
- Less actively maintained, with fewer recent updates
- Documentation is not as extensive or well-organized
- Larger codebase, potentially leading to a steeper learning curve
Code Comparison
Image:
$image = new \Gregwar\Image\Image('path/to/image.jpg');
$image->resize(100, 100)
->negate()
->save('output.jpg');
image:
$image = Image::load('path/to/image.jpg');
$image->width(100)
->height(100)
->save('output.jpg');
The Image library offers more advanced manipulation methods out of the box, while image focuses on a simpler, more streamlined API. Image provides methods like negate()
for quick effects, whereas image requires separate manipulation classes for such operations.
Both libraries offer straightforward ways to load, resize, and save images. However, Image's API tends to be more verbose, allowing for chaining of multiple operations in a single statement. The image library, on the other hand, emphasizes a cleaner, more modular approach to image manipulation.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Manipulate images with an expressive API
Image manipulation doesn't have to be hard. Here are a few examples on how this package makes it very easy to manipulate images.
use Spatie\Image\Image;
// modifying the image so it fits in a 100x100 rectangle without altering aspect ratio
Image::load($pathToImage)
->width(100)
->height(100)
->save($pathToNewImage);
// overwriting the original image with a greyscale version
Image::load($pathToImage)
->greyscale()
->save();
// make image darker and save it in low quality
Image::load($pathToImage)
->brightness(-30)
->quality(25)
->save();
// rotate the image and sharpen it
Image::load($pathToImage)
->orientation(90)
->sharpen(15)
->save();
You'll find more examples in the full documentation.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
composer require spatie/image
Please note that since version 1.5.3 this package requires exif extension to be enabled: http://php.net/manual/en/exif.installation.php
Usage
Head over to the full documentation.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Testing
npm i pixelmatch
composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you've found a bug regarding security please mail security@spatie.be instead of using the issue tracker.
Postcardware
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.
We publish all received postcards on our company website.
Credits
Large parts of this codebase were copied from Intervention Image by Oliver Vogel, and modified for readability and to fit our needs.
License
The MIT License (MIT). Please see License File for more information.
Top Related Projects
Wonderfully easy on-demand image manipulation library with an HTTP based API.
PHP Image Processing
PHP Object Oriented image manipulation library
A PHP class that makes working with images and GD as simple as possible.
A PHP library to handle images
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot