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

Related tags

Imagery glide
Overview

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.

Comments
  • Flysystem v2

    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)
    opened by ADmad 30
  • Suggestion for improving performance

    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.

    opened by freekmurze 29
  • Cleaning up the cache

    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.

    enhancement 
    opened by reinink 20
  • Fixed jpeg progressive and make sure temp image is deleted

    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

    opened by thomaspicquet 18
  • NGiNX try_files support

    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?

    opened by Zae 18
  • Focal point support

    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.

    enhancement 
    opened by ducktype 18
  • Response times increase when making glide requests in a loop

    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?

    opened by johncarter- 14
  • Image issues

    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?
    help wanted 
    opened by scott-davidjones 14
  • Watermarking support

    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
    ]);
    
    enhancement 
    opened by jackmcdade 14
  • Face detection

    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
    
    enhancement 
    opened by reinink 13
  • Add

    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.

    opened by kjellknapen 12
  • Could not find the image error in Laravel

    Could not find the image error in Laravel

    Hello,

    I have a weird issue with Glide on a fresh local Laravel install (PHP 8.1.13 / Laravel 9.44.0). I followed the documentation to the letter, my route looks like this:

    Route::get('/img/{path}', [ImageController::class, 'show'])->where('path', '.*');

    I have an ImageController that looks like this:

    namespace App\Http\Controllers;
    
    use Illuminate\Contracts\Filesystem\Filesystem;
    use League\Glide\Responses\LaravelResponseFactory;
    use League\Glide\ServerFactory;
    
    class ImageController extends Controller
    {
        public function show(Filesystem $filesystem, $path)
        {
            $server = ServerFactory::create([
                'response' => new LaravelResponseFactory(app('request')),
                'source' => $filesystem->getDriver(),
                'cache' => $filesystem->getDriver(),
                'cache_path_prefix' => '.cache',
            ]);
    
            return $server->getImageResponse($path, request()->all());
        }
    }
    

    But when I try to access an image through the correct path, it gives me a "Could not find the image storage/images/portrait-rose.jpg." error.

    Url is: http://localhost:8000/img/storage/images/portrait-rose.jpg

    And if I try to access http://localhost:8000/storage/images/portrait-rose.jpg the image definitely shows up. What could be the issue there?

    Thanks in advance.

    opened by Exoseed 0
  • Mockery error in League\Glide\ServerTest::testMakeImageFromSource

    Mockery error in League\Glide\ServerTest::testMakeImageFromSource

    I'm running the glide test suite on PHP 8.1, and it all passes except for one thing:

    1) League\Glide\ServerTest::testMakeImageFromSource
    Mockery\Exception\NoMatchingExpectationException: No matching handler found for
    Mockery_8_League_Glide_Api_ApiInterface::run('/private/var/folders/wn/fk5c4mz15z56v0ztf3g4c5dh0000gn/T/GlideUCfJUM', []). 
    Either the method was unexpected or its arguments matched no expected argument list for this method
    

    I don't understand this error, but I figure it shouldn't be failing!

    opened by Synchro 1
  • [ feature ] Save resized files to another directory with different link

    [ feature ] Save resized files to another directory with different link

    Parsing URL with security key causes performance on lots of requests (image gallery)

    You have to keep in mind - html code makes tonns of async requests to your server that should start framework or even if you create native php file with configured Glide - even then launching PHP to just check signature - useless thing.

    It should be like this: glide makes url to resize if image still not resized, but makes url to static file if it is already done.

    Is it a good idea, you think?

    opened by 6562680 0
  • Add

    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

    opened by adrenth 1
  • Some images converted to webp format has response type

    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

    opened by Aleksey203SkyUp 0
Releases(1.7.1)
  • 1.7.1(Apr 27, 2022)

    What's Changed

    • [1.x] Fix PHP 8.1 deprecations by @erikn69 in https://github.com/thephpleague/glide/pull/350

    New Contributors

    • @erikn69 made their first contribution in https://github.com/thephpleague/glide/pull/350

    Full Changelog: https://github.com/thephpleague/glide/compare/1.6.1...1.7.1

    Source code(tar.gz)
    Source code(zip)
  • 2.2.2(Feb 21, 2022)

    What's Changed

    • Enable TIFF image format handling, fixes #344 by @Synchro in https://github.com/thephpleague/glide/pull/345

    New Contributors

    • @Synchro made their first contribution in https://github.com/thephpleague/glide/pull/345

    Full Changelog: https://github.com/thephpleague/glide/compare/2.2.1...2.2.2

    Source code(tar.gz)
    Source code(zip)
  • 2.2.1(Jan 14, 2022)

    What's Changed

    • allow league/flysystem v3 by @Nielsvanpach in https://github.com/thephpleague/glide/pull/340

    New Contributors

    • @Nielsvanpach made their first contribution in https://github.com/thephpleague/glide/pull/340

    Full Changelog: https://github.com/thephpleague/glide/compare/2.2.0...2.2.1

    Source code(tar.gz)
    Source code(zip)
  • 2.2.0(Jan 11, 2022)

    What's Changed

    • Add "fill-max" resizing option by @kjellknapen in https://github.com/thephpleague/glide/pull/332

    New Contributors

    • @kjellknapen made their first contribution in https://github.com/thephpleague/glide/pull/332

    Full Changelog: https://github.com/thephpleague/glide/compare/2.1.1...2.2.0

    Source code(tar.gz)
    Source code(zip)
  • 2.1.1(Dec 9, 2021)

    What's Changed

    • Fix PHP 8.1 deprecations by @bastien-phi in https://github.com/thephpleague/glide/pull/337

    New Contributors

    • @bastien-phi made their first contribution in https://github.com/thephpleague/glide/pull/337

    Full Changelog: https://github.com/thephpleague/glide/compare/2.1.0...2.1.1

    Source code(tar.gz)
    Source code(zip)
  • 2.1.0(Oct 26, 2021)

  • 1.6.1(May 20, 2021)

  • 2.0.0(Mar 4, 2021)

    This release is a major release: it may introduce Backward Compatibility issues in your project. Please be careful when you upgrade.

    This release is mostly focused on migrating to Flysystem 2.0. It introduces a few BC breaks to use the new interfaces and abstractions but it should be quite straightforward to upgrade.

    • BC break Migrate to Flysystem 2 (https://github.com/thephpleague/glide/pull/301)
    • Fix rounding issue (https://github.com/thephpleague/glide/pull/310)
    • Allow to configure the temporary directory used (https://github.com/thephpleague/glide/pull/304)
    Source code(tar.gz)
    Source code(zip)
  • 1.7.0(Nov 12, 2020)

  • 1.6.0(Jul 7, 2020)

  • 1.5.0(Apr 3, 2019)

  • 1.4.0(Dec 22, 2018)

  • 1.3.0(Feb 12, 2018)

  • 1.2.2(May 9, 2017)

  • 1.2.1(Jan 19, 2017)

  • 1.2.0(Nov 14, 2016)

  • 1.1.1(Nov 14, 2016)

  • 1.1.0(Aug 19, 2016)

  • 1.0.1(Jun 13, 2016)

  • 0.3.6(Jan 25, 2016)

  • 1.0.0(Dec 26, 2015)

    Source code(tar.gz)
    Source code(zip)
  • 0.3.5(May 22, 2015)

  • 0.3.4(May 22, 2015)

  • 0.3.3(Mar 19, 2015)

  • 0.3.2(Feb 26, 2015)

    • Added graceful handling of cache write failure due to already existent cache file caused by race condition. Thanks @kevin-thackorie! #38 #39
    • Added note to README about security.
    Source code(tar.gz)
    Source code(zip)
  • 0.3.1(Feb 2, 2015)

  • 0.3.0(Jan 28, 2015)

    • Large refactor for improve code organization. Many classes moved and renamed.
    • Changed league/flysystem dependency to version 1.x. Nice work @frankdejonge!
    • Responses will now return 304 Not Modified on subsequent requests. #20
    • Added new source path prefix option to Server, with setSourcePathPrefix() and getSourcePathPrefix() methods. #26
    • Added new cache path prefix option to Server, with setCachePathPrefix() and getCachePathPrefix() methods. #26
    • Added new source_path_prefix and cache_path_prefix options to ServerFactory. #26
    • Added new FilesystemException\FilesystemException exception, and additional file system checks.
    • Changed manipulators to return an instance of Intervention\Image\Image. This allows for more rigorous manipulations to occur. #25
    • Updated output manipulator to use source format when format is not set or invalid. Previously this was set to jpg by default. #24
    • Renamed server method getSourceFilename() to getSourcePath(), and getCacheFilename() to getCachePath().
    • Removed $baseUrl parameter from the Server constructor. Use setBaseUrl() method instead.
    Source code(tar.gz)
    Source code(zip)
  • 0.2.0(Jan 8, 2015)

    • Removed sign_key option from the Server class. For simplicity HTTP signatures are now configured and managed separately from the server.
    • Renamed SignKey to HttpSignature.
    • Renamed InvalidTokenException to InvalidSignatureException.
    • Added new HttpSignature interface, allowing for custom implementations.
    • Added new HttpSignature and UrlBuilder factories.
    • Added new base URL option to server class.
    Source code(tar.gz)
    Source code(zip)
  • 0.1.1(Jan 6, 2015)

    • Added new cacheFileExists and sourceFileExists methods to server.
    • Updated getCacheFilename method to accept a Request object or $filename, $params combination.
    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Jan 6, 2015)

Owner
The League of Extraordinary Packages
A group of developers who have banded together to build solid, well tested PHP packages using modern coding standards.
The League of Extraordinary Packages
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,

Erik Nielsen 455 Dec 30, 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

Bulat Shakirzyanov 4.3k Jan 6, 2023
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

Ian Selby 985 Dec 4, 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

TheCodeholic 42 Dec 15, 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

null 13k Jan 3, 2023
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

Piotr Śliwa 879 Dec 30, 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

QCode.in 708 Dec 22, 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

Creativeorange 477 Dec 1, 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. Introduction How to use? Go to Gutenberg Editor and add a image block. e.g. Add new image

Mahesh Waghmare 3 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

null 135 Dec 4, 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

Liip 1.6k Dec 30, 2022
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

Erika Heidi 67 Nov 22, 2022
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

Franck Alary 17 Nov 13, 2022
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

Grégoire Passault 958 Dec 29, 2022
🌄 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

Jens Segers 1.9k Dec 28, 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

Will Washburn 58 Nov 30, 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

The League of Extraordinary Packages 1.2k Jan 1, 2023
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

Thomas 56 Dec 16, 2022
A simple page view counter that store data as text and shows data as a PNG image

Image Counter A simple page view counter that store data as text and shows the counter as a PNG image.

Victor Ribeiro 10 Apr 19, 2022