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

Last update: Jun 23, 2022

Glide

Latest Version Software License Build Status Code Coverage Total Downloads Source Code Author Author

Glide is a wonderfully easy on-demand image manipulation library written in PHP. Its straightforward API is exposed via HTTP, similar to cloud image processing services like Imgix and Cloudinary. Glide leverages powerful libraries like Intervention Image (for image handling and manipulation) and Flysystem (for file system abstraction).

© Photo Joel Reynolds

© Photo Joel Reynolds

Highlights

  • Adjust, resize and add effects to images using a simple HTTP based API.
  • Manipulated images are automatically cached and served with far-future expires headers.
  • Create your own image processing server or integrate Glide directly into your app.
  • Supports both the GD library and the Imagick PHP extension.
  • Supports many response methods, including PSR-7, HttpFoundation and more.
  • Ability to secure image URLs using HTTP signatures.
  • Works with many different file systems, thanks to the Flysystem library.
  • Powered by the battle tested Intervention Image image handling and manipulation library.
  • Framework-agnostic, will work with any project.
  • Composer ready and PSR-2 compliant.

Documentation

Full documentation can be found at glide.thephpleague.com.

Installation

Glide is available via Composer:

$ composer require league/glide

Testing

Glide has a PHPUnit test suite. To run the tests, run the following command from the project folder:

$ phpunit

Contributing

Contributions are welcome and will be fully credited. Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see LICENSE for more information.

GitHub

https://github.com/thephpleague/glide
Comments
  • 1. Flysystem v2

    This PR contains:

    • Code formatting updated to PSR12 standard
    • Added strict typing (and static analysis check using Psalm)
    • Upgraded Glide to v2
    • ~~Added support for running testsuite on PHP 8~~ New Github Actions worfklow file (as TravisCI builds are extremely backlogged)
    Reviewed by ADmad at 2020-10-24 06:39
  • 2. Suggestion for improving performance

    At the moment, when a client request an image, a php process on the server must be started to transfer the image to the client. For a low traffic website this won't be a problem, but for a high traffic site the server might get flooded with requests to transfer images.

    One possible way to avoid invoking php when an image gets requested is to create the image on the path of the request url.

    Let me clarify that a bit. Instead of using get parameters to specify how an image should be manipulated, a regular url should be used. Eg: https://glide.herokuapp.com/height/100/with/500/sharp/2/kayaks.jpg If this manipulation does not already exist in cache, create it in the public folder of the server using path "/height/100/with/500/sharp/2/kayaks.jpg" and return the image via php. The next client that comes by to retrieve that manipulation won't trigger php on the server as the webserver will return the cached file on the filesystem.

    I hope this suggestion is a bit clear.

    Reviewed by freekmurze at 2015-01-07 12:37
  • 3. Cleaning up the cache

    Currently Glide does not do any cache cleanup, meaning it generates manipulated images and places them into the cache file system, but it never deletes them. It's possible that over time this cache gets large and contains many unused image manipulations.

    The simple solution here is to simply delete the entire cache periodically, and on small projects this is probably fine. But on larger projects it could be problematic since all image manipulations will have to be regenerated.

    It would probably be good if Glide came with a CacheCleanup helper. This cleanup tool could be run every time a request is received, or it could be setup with a scheduler (probably better). Something like:

    $cache = new Filesystem(new LocalAdapter('cache-folder'));
    $cleanup = new CacheCleanup($cache)
    $cleanup->expire(2592000); // 30 days
    

    This approach would delete any manipulations older than 30 days. This can be determined easily use the $filesystem->getTimestamp() method.

    However, this technique will not take into consideration whether they are being actively accessed or not. Using the last accessed date would be much more complicated since this information is not readily available. To do this you would need to create a data store, and save this information every time a manipulation is created. I feel this falls outside of the scope of this project. If this sort of cache cleanup is needed, developers are welcome to implement this themselves.

    Reviewed by reinink at 2015-01-01 14:37
  • 4. Fixed jpeg progressive and make sure temp image is deleted

    I run glide on a very large site, lots of traffic and we had issues with the temp image filling up the server just because one image was broken, also the part setting the jpeg image in a white image was breaking the progressive jpeg format. I don't see the utility of it so I removed it. I can put it back for jpeg only, it just doesn't work for progressive jpeg

    Reviewed by thomaspicquet at 2016-05-27 15:17
  • 5. NGiNX try_files support

    Because after #7 glide stores images with the query params as md5 in the filename there is not easy way to use try_files to let nginx find the cached image itself and speed up the whole process a lot.

    Is there an easy way to change how getCachePath generates the filenames so I can make them so that nginx can find them?

    Reviewed by Zae at 2015-07-25 12:41
  • 6. Focal point support

    Actually does not seems possible to specify a custom centering point for resize fit/crop operations.

    Some cms allow the user to specify the focus coordinates for each image.

    I propose to add an argument like this focal_coords=20%:70% to say that the focal point will be at 20% x and 70% y.

    Reviewed by ducktype at 2015-02-23 23:05
  • 7. Response times increase when making glide requests in a loop

    I am building a Laravel 8 app. I have some images related to products.

    When I loop the images the response times from my local environment grow with each request. See the screenshot:

    image

    I am using the exact code from the controller shown in the docs:
    https://glide.thephpleague.com/1.0/config/integrations/laravel/#installation

    My route is:
    Route::get('glide/{path}', [App\Http\Controllers\GlideImageController::class, 'show'])->where('path', '.*');

    And my view looks like this:

    <x-test-layout>
    
        @foreach ($products as $product)
        {{-- <img class="max-w-sm" src="/storage/{{ $product->imageUrl() }}" alt=""> --}}
        <img class="max-w-sm" src="/glide/{{ $product->imageUrl() }}" alt="">
        @endforeach
    
    </x-test-layout>
    

    The non- N.B. x-test-layout is just a bare bones html boiler plate.

    Can anyone tell me what am I doing wrong?

    Reviewed by johncarter- at 2020-10-22 15:54
  • 8. Image issues

    Hi,

    I am using this lib as part of a laravel 4.2 instalation with the following code:

    $server = League\Glide\ServerFactory::create([
        'source' => public_path()."/uploads",
        'cache' => public_path()."/uploads/imgCache",
    ]);
    
    Route::get('/loadimage/{type}/{id}/{width}/{height}/{crop}/{name}', function($type, $id, $width, $height, $crop, $name) use ($server){ 
        $server->outputImage(
              $type.'/'.$id.'/'.$name,
               [
                    'w' => $width,
                    'h' => $height,
                    'fit' => ($crop == 1 ? 'crop':'max'),
               ]
        );
    });
    

    I am having some very weird issues:

    • Some times when refreshing a page i just get an image and nothing else
    • Sometimes a variety of images on the page are all showing the same image (even if they are not called using the same path)
    • sometimes images take ages to load and thus dont display in email clients (such as outlook) however they work fin else were - it seems like the caches images are not being used as its recreating them every time?
    Reviewed by scott-davidjones at 2015-06-16 09:55
  • 9. Watermarking support

    We'd love to see (and be helpful in adding, if possible) Intervention\Image's watermark support come to Glide.

    I would imagine the HTTP API could be a bit of an awkward place to try and manage that, so I wonder if it's something you could configure on the ServerFactory config or something, and then either allow a watermark=true parameter or force it to always be on for those server instance requests.

    Perhaps something like this?

    ServerFactory::create([
        'source'    => config('glide.source'),
        'cache'     => config('glide.cache'),
        'watermark' => config('glide.watermark') // would point to /img/watermark.png or similar
    ]);
    
    Reviewed by jackmcdade at 2015-06-02 13:00
  • 10. Face detection

    It would be awesome to add face detection to the crop function. This might be a bit of a pipe dream. There is this PHP package. Also, could be good to look at this JavaScript project.

    Function would work like this:

    kayaks.jpg?w=500&h=500&crop=face
    
    Reviewed by reinink at 2015-01-08 18:51
  • 11. Add "fill-max" resizing option

    I noticed the issue for #206 had a pull request but it hadn't been merged yet because of naming issues. So I went to check in the Imgix api and made changes accordingly. In the imgix api the fill function is used for resizing and filling an image (so this function shoud actually do what is requested in the issue).

    So in my PR I changed this function to the function made by @xor22h in the previous PR. Next to that I added the fillmax function to allow users to also fill and preserve ratio as the fill function used to do. If you rather have them the other way around I can change it since this would be a change affecting everyone using the fill method.

    Reviewed by kjellknapen at 2021-10-07 06:34
  • 12. Add "fill-max" resizing option

    Added the "fill-max" resizing option to the version 1.x branch. So that users which kept stuck at version 1.x can use this resizing option.

    The code was taken from PR #332 which is now part of version 2.x

    Reviewed by adrenth at 2022-03-17 15:42
  • 13. Break out the list of supported image formats

    ...so that it's visible from outside. As far as I can see there is no public way to obtain a list of the image formats that glide supports (other than docs), so I've moved it to a static method in the Encode Manipulator, and I use that from its own methods too. It's static so it can be overridden easily if someone wants to add (or remove) a format.

    This is just an idea – I found that I wanted to find this out when using glide from spatie/image, as otherwise it has to maintain its own list of supported formats, which isn't very DRY.

    Reviewed by Synchro at 2022-02-21 19:53
  • 14. Some images converted to webp format has response type "octet-stream" and are empty in browser

    Some images converted to webp format has response type "octet-stream" and are empty in browser.

    If copy link of image and put it into new tab everything is good.

    The problem was resolved by removing raw: header('Content-Length:'.$this->cache->fileSize($path));

    In the public function outputImage($path, array $params) file Server.php

    Reviewed by Aleksey203SkyUp at 2022-01-23 10:13
  • 15. Should filter $params against available manipulations/params

    Great package! I'm building a wordpress implementation of glide (will share when finished) and I've found what I consider is a slight bug in the handling of query string manipulations.

    I think params should be filtered by defined params because any arbitrary query string variables will create new images

    <img src="/img/users/myimage.jpg?w=300&h=400&fit=crop">
    <img src="/img/users/myimage.jpg?w=300&h=400&fit=crop&asdf=asdf">
    <img src="/img/users/myimage.jpg?w=300&h=400&fit=crop&qwer=qwer">
    

    Will all create new images, technically they should be the same image as the additional query string variables do not constitute a new variant. Currently three cache images are created and I'm assuming that has to do with the name of cache files being a hash of the parameters.

    Just a quick couple quick functions/methods for filtering below (minimally tested). I haven't got into the source yet to see where this would need to go, but when I do I'll try and put in a pull request.

    
    function getQueryStringManipulationsAllowed(): array
    {
        // https://glide.thephpleague.com/2.0/api/quick-reference/
        return [
            'or',
            'flip',
            'crop',
            'w',
            'h',
            'fit',
            'dpr',
            'bri',
            'con',
            'gam',
            'sharp',
            'blur',
            'pixel',
            'filt',
            'mark',
            'markw',
            'markh',
            'markx',
            'marky',
            'markpad',
            'markpos',
            'markalpha',
            'bg',
            'border',
            'q',
            'fm',
        ];
    }
    
    // this method would need any other qs variables accepted!!
    function getQueryStringOther(): array
    {
        return [
            'p', // preset
            's', // security signature
        ];
    }
    
    function getQueryStringFiltered(array $params): array
    {
        $merged = array_merge(getQueryStringManipulationsAllowed(), getQueryStringOther());
        return array_intersect_key($params, array_flip($merged));
    }
    
    
    
    Reviewed by midweste at 2021-10-29 16:49
  • 16. How to avoid image-resize attacks from side requests ?

    Hello!

    I am using Glide in my Images service to manipulate images from side resources via Rest API https://flextype.org/documentation/rest-api/images like it is https://imgix.com.

    I see this example here https://glide.thephpleague.com/2.0/simple-example/

    <img src="/img/users/<?=$user->id?>.jpg?w=300&h=400&fit=crop">
    

    and it is fine to build urls in this way,

    but then I read this: https://glide.thephpleague.com/2.0/config/security/ it's saying that it is not secure and we should use signatures and build URLs with help of UrlBuilderFactory.

    GET /api/images/{path:.+}?VALID_ARGUMENTS&token=YOUR_IMAGES_TOKEN
    

    I know know my YOUR_IMAGES_TOKEN but image signature is unique per each request.

    And even on the current server I can't create request to the API by typing url with arguments, because it requires signature for security reason.

    on https://imgix.com example, I don't see signatures (or I am wrong), how do they protect server from image-resize attacks ? any ideas ?

    Is there some simple way to make secure requests without UrlBuilderFactory? Is it possible to get signatures out of the server somehow in simple way? Or maybe there is any other ways to protect server from image-resize attacks ?

    Reviewed by Awilum at 2021-09-01 18:58
Related tags
Image Cache is a very simple PHP class that accepts an image source and will compress and cache the file, move it to a new directory, and returns the new source for the image.

NO LONGER MAINTAINED!!! Image Cache v. 1.0.0 Image Cache is a very simple PHP class that accepts an image source and will compress and cache the file,

Jun 16, 2022
PHP 5.3 Object Oriented image manipulation library

Imagine Tweet about it using the #php_imagine hashtag. Image manipulation library for PHP 5.3 inspired by Python's PIL and other image libraries. Requ

Jun 30, 2022
PHP Thumb is a light-weight image manipulation library aimed at thumbnail generation

PHP Thumb NOTICE - This project was recently updated to 2.0 and is PSR-0 compliant and supports Composer integration. Some parts of the documentation

Jun 23, 2022
This is an image manipulation REST API written in PHP Laravel Framework

Laravel Image Manipulation REST API Demo Here is fully working Demo: https://www.lobiimages.com/ You have to register first in order to generate acces

Jun 24, 2022
PHP Image Manipulation

Intervention Image Intervention Image is a PHP image handling and manipulation library providing an easier and expressive way to create, edit, and com

Jun 30, 2022
Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.

Image Optimizer This library is handy and very easy to use optimizer for image files. It uses optipng, pngquant, jpegoptim, svgo and few more librarie

Jun 16, 2022
Auto Image & file upload, resize and crop for Laravel eloquent model using Intervention image

Laravel ImageUp The qcod/laravel-imageup is a trait which gives you auto upload, resize and crop for image feature with tons of customization. Install

Jun 11, 2022
A Laravel Gravatar package for retrieving gravatar image URLs or checking the existance of an image.

Gravatar for Laravel 5.x, 6, 7 and 8 Installation First, pull in the package through Composer via the command line: composer require creativeorange/gr

Jun 21, 2022
This plugin adds a new image style for the Core Image block.
This plugin adds a new image style for the Core Image block.

This plugin adds a new image style for the Core Image block. Introduction How to use? Go to Gutenberg Editor and add a image block. e.g. Add new image

Feb 17, 2022
PHPExif is a library which gives you easy access to the EXIF meta-data of an image

PHPExif v0.6.4 PHPExif is a library which gives you easy access to the EXIF meta-data of an image. PHPExif serves as a wrapper around some native or C

Apr 29, 2022
Symfony Bundle to assist in imagine manipulation using the imagine library

LiipImagineBundle PHPUnit PHP-CS-Fixer Coverage Downloads Release This bundle provides an image manipulation abstraction toolkit for Symfony-based pro

Jun 22, 2022
php-gd based image templates
php-gd based image templates

gdaisy A highly experimental image templating system based on PHP-GD to dynamically generate image banners and covers. Installation 1. Require erikahe

Jun 14, 2022
PHP library to easily edit image with GD extension. Resize, crop, merge, draw, and many more options !
PHP library to easily edit image with GD extension. Resize, crop, merge, draw, and many more options !

PHP Image Editor PHP library to easily edit image with GD extension. Resize, crop, merge, draw, and many more options ! ✨ Supporting ⭐ Star this repos

Jun 8, 2022
The Gregwar\Image class purpose is to provide a simple object-oriented images handling and caching API
The Gregwar\Image class purpose is to provide a simple object-oriented images handling and caching API

Gregwar's Image class The Gregwar\Image class purpose is to provide a simple object-oriented images handling and caching API. Installation With compos

Jun 30, 2022
ImageWorkshop is a PHP5.3+ library that helps you to manage images based on GD library

================================ ImageWorkshop class ================================ Summary and features Really flexible and easy-to-use PHP class t

Jun 16, 2022
🌄 Perceptual image hashing for PHP
🌄 Perceptual image hashing for PHP

ImageHash A perceptual hash is a fingerprint of a multimedia file derived from various features from its content. Unlike cryptographic hash functions

Jun 24, 2022
:racehorse: find the size of an image without downloading the whole file. Supports batch requests.

FasterImage FasterImage finds the dimensions or filetype of a remote image file given its uri by fetching as little as needed, based on the excellent

Apr 9, 2022
Extract colors from an image like a human would do.

ColorExtractor Extract colors from an image like a human would do. Install Via Composer $ composer require league/color-extractor:0.3.* Usage require

Jun 17, 2022
An open source image hosting service powered by Laravel
 An open source image hosting service powered by Laravel

Limg An open source image hosting service powered by Laravel Features Upload your image via file, url or ShareX ! Manage your image (custom title, pub

Jun 16, 2022