Download the PHP package ambroisemaupate/intervention-request without Composer

On this page you can find all versions of the php package ambroisemaupate/intervention-request. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package intervention-request

Intervention Request

A customizable Intervention Image wrapper to use image simple re-sampling features over urls and a configurable cache.

Build Status Packagist Packagist

Ready-to-go Docker image

Intervention Request is now available as a standalone Docker server to use with whatever CMS or language you need:

Garbage collector runs every hour as a crontab job and will purge cache files created more than $IR_GC_TTL seconds ago.

Use local file-system or a distant one

InterventionRequest is built on Flysystem library to abstract access to your native images. Then you can store all your images on an AWS bucket or a Scaleway Object Storage and process them on the fly. Processed images are still cached on InterventionRequest local storage. This new file system abstraction layer allows multiple InterventionRequest docker containers to run in parallel but still use the same storage as image backend, or simply detach your media storage logic from InterventionRequest application.

InterventionRequest object requires a FileResolverInterface which can be a LocalFileResolver or FlysystemFileResolver, then FlysystemFileResolver must be provided a League\Flysystem\Filesystem object configured with any Flysystem adapter.

If you prefer to use ambroisemaupate/intervention-request Docker image, environment variables are available for AWS adapter only.

Docker Compose example

You don’t need to read further if you do not plan to embed this library in your PHP application.

Install

Intervention Request is based on symfony/http-foundation component for handling HTTP request, response and basic file operations. It wraps Intervention/image feature with a simple file cache managing.

Configuration

Intervention request use a dedicated class to configure your image request parameters. Before creating InterventionRequest object, you must instantiate a new AM\InterventionRequest\Configuration object and set cache and images paths.

This code will create a configuration with cache and images folders in the same folder as your PHP script (APP_ROOT). Notice that in the default index.php file, images path is defined to /test folder in order to use the testing images. You should always set this path against your website images folder to prevent processing other files.

You can edit each configuration parameters using their corresponding setters:

Available operations

Query attribute Description Usage
image Native image path relative to your configuration imagePath ?image=path/to/image.jpg
fit Crop and resize combined It needs a width and a height in pixels, this filter can be combined with align to choose which part of your image to fit …&fit=300x300
align Crop and resize combined Choose which part of your image to fit. …&align=c
flip Mirror image horizontal or vertical You can set h for horizontal or v for vertical flip. …&flip=h
crop Crop an image It needs a width and a height in pixels …&crop=300x300
width Resize image proportionally to given width It needs a width in pixels …&width=300
height Resize image proportionally to given height It needs a height in pixels …&height=300
crop + height/width Do the same as fit using width or height as final size …&crop=300x300&width=200: This will output a 200 x 200px image
background Matte a png file with a background color …&background=ff0000
greyscale/grayscale Turn an image into a greyscale version …&greyscale=1
blur Blurs an image …&blur=20
quality Set the exporting quality (1 - 100), default to 90 …&quality=95
progressive Toggle progressive mode …&progressive=1
interlace Toggle interlaced mode …&interlace=1
sharpen Sharpen image (1 - 100) …&sharpen=10
contrast Change image contrast (-100 to 100, 0 means no changes) …&contrast=10
no_process Disable all image processing by PHP, this does not load image in memory but executes any post-process optimizers (such as pngquant, jpegoptim…) …&no_process=1

Fit position

Due to URL rewriting, align filter can only takes one or two letters as a value. When no align filter is specified, center is used:

URL value Alignment
tl top-left
t top
tr top-right
l left
c center
r right
bl bottom-left
b bottom
br bottom-right

Using standalone entry point

An index.php file enables you to use this tool as a standalone app. You can adjust your configuration to set your native images folder or enable/disable cache.

Setup it on your webserver root, in a intervention-request folder and call this url (for example using MAMP/LAMP on your computer with included test images): http://localhost:8888/intervention-request/?image=images/testPNG.png&fit=100x100

Using as a library inside your projects

InterventionRequest class works seamlessly with Symfony Request and Response. It’s very easy to integrate it in your Symfony controller scheme:

Use URL rewriting

If you want to use clean URL. You can add ShortUrlExpander class to listen to shorten URL like: http://localhost:8888/intervention-request/f100x100-g/images/testPNG.png.

First, add an .htaccess file (or its Nginx equivalent) to activate rewriting:

Then add these lines to your application before handling InterventionRequest. ShortUrlExpander will work on your existing $request object.

Shortcuts

URL shortcuts can be combined using - (dash) character. For example f100x100-q50-g1-p0 stands for fit=100x100&quality=50&greyscale=1&progressive=0.

Query attribute Shortcut letter
align a
fit f
flip m
crop c
width w
height h
background b
greyscale g
blur l
quality q
progressive p
interlace i
sharpen s
contrast (only from 0 to 100) k
no_process (do not process and load image in memory, allows optimizers) n

Use pass-through cache

Intervention request can save your images in a public folder to let Apache or Nginx serve them once they’ve been generated. This can reduce time-to-first-byte as PHP is not called any more.

Define your configuration cache path to a public folder:

Then enable the ShortUrlExpander and ignore your cache path to process only path info after it.

Convert to webp

Make sure your PHP is compiled with WebP image format.

Intervention Request can automatically generated webp images by appending .webp to an existing image file.

Use /image.jpg.webp for /image.jpg file.

Intervention Request will look for a image file without .webp extension and throw a 404 error if it does not exist.

Force garbage collection

Using command-line

Extend Intervention Request

Intervention Request uses Processors to alter original images. By default, each available operation is handled by one AbstractProcessor inheriting class (look at the src/Processor folder).

You can create your own Processors and override default ones by injecting an array to your InterventionRequest object.

Be careful, Processors position in this array is very important, please look at the default one in InterventionRequest.php class. Resizing processors should be the first, and quality processors should be the last as image operations will be done following your processors ordering.

Add custom event subscribers

You can create custom actions if you need to optimize/alter your images before they get served using ImageSavedEvent and Symfony event system :

Create a class implementing ImageEventSubscriberInterface and, for example, listen to ImageSavedEvent::NAME

This event will carry a ImageSavedEvent object with all you need to optimize/alter it. Then, use $interventionRequest->addSubscriber($yourSubscriber) method to register it.

Available events

Event name Description
RequestEvent::class Main request handling event which handles quality and image processing and caching.
ImageBeforeProcessEvent::class Before Image is being processed.
ImageAfterProcessEvent::class After Image has been processed.
ImageSavedEvent::class After Image has been saved to filesystem with a physical file-path. This event is only dispatched if caching is enabled.
ResponseEvent::class After Symfony’s response has been built with image data. (Useful to alter headers)

Listener examples

Of course, you can build your own listeners and share them with us!

Performances

If your Intervention-request throws errors like that one:

It’s because you are trying to process a too large image. The solution is too increase your memory_limit PHP setting over 256M. You can edit this file in your server php.ini file.

You can use ini_set('memory_limit', '256M'); in your index.php file if your hosting plan allows you to dynamically change PHP configuration.

In general, we encourage to always downscale your native images before using them with Intervention-request. Raw jpeg images coming from your DSLR camera will give your PHP server a very hard time to process.

Optimization

jpegoptim

If you have jpegoptim installed on your server, you can add it to your configuration

pngquant

If you have pngquant installed on your server, you can add it to your configuration

oxipng

If you have oxipng installed on your server, you can add it to your configuration

pingo

If you have pingo installed on your server and Wine, you can add it to your configuration

kraken.io

If you have subscribed to a paid kraken.io plan, you can add the dedicated KrakenListener to send your resized images over the external service.

Pay attention, that images will be sent over kraken.io API, it will take some additional time.

tinyjpg.com

If you have subscribed to a paid tinyjpg.com plan, you can add the dedicated TinifyListener to send your resized images over the external service.

Pay attention, that images will be sent over kraken.io API, it will take some additional time.

jpegtran

If you want to use your system jpegtran or the Mozjpeg one, you can use the JpegTranListener.

Optimization benchmark

With default quality to 90%. \ AVIF conversion only supports custom compiled ImageMagick and only support lossless encoding.

Url PHP raw tinyjpg.com Kraken.io + lossy jpegoptim mozjpeg (jpegtran) WebP (90%) WebP (85%) AVIF (100%)
/test/images/testUHD.jpg?width=2300 405 kB 168 kB 187 kB 395 kB 390 kB 235 kB 155 kB 94 kB
/test/images/testUHD.jpg?width=1920 294 kB 132 kB 134 kB 285 kB 282 kB 176 kB 115 kB 71 kB
/test/images/rhino.jpg?width=1920 642 kB 278 kB 534 kB 598 kB 596 kB 564 kB 429 kB 398 kB
/test/images/rhino.jpg?width=1280 325 kB 203 kB 278 kB 303 kB 301 kB 295 kB 229 kB 227 kB
Url PHP raw pngquant oxipng Kraken.io + lossy WebP (100%) WebP (85%) AVIF (100%)
/test/images/testPNG.png 292 kB 167 kB 288 kB 142 kB 186 kB 28 kB 11.7 kB

License

Intervention Request is handcrafted by Ambroise Maupate under MIT license.

Have fun!

Testing

Copy index.php to dev.php then launch PHP server command using router.php as router.

Then open http://0.0.0.0:8088/dev.php/w300/rhino.jpg in your browser. You should be able to test intervention-request with ShortUrl enabled.

If you want to test pass-through cache, uncomment dev.php lines 46 and 56 and open http://0.0.0.0:8088/dev.php/cache/w300/rhino.jpg instead. First time request will be serve by PHP (look up at response headers), then following requests will be handled directly by your server (no more Intervention Request headers).


All versions of intervention-request with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
ext-gd Version *
ext-curl Version *
intervention/image Version ^2.5.1
league/flysystem Version ^3.0
league/flysystem-memory Version ^3.0
monolog/monolog Version ^1.22 || ^2.1.1 || ^3.3.1
symfony/console Version ^4.4 || ^5.0.7 || ^6.2
symfony/event-dispatcher Version ^4.4 || ^5.0.7 || ^6.2
symfony/filesystem Version ^4.4 || ^5.0.7 || ^6.2
symfony/finder Version ^4.4 || ^5.0.7 || ^6.2
symfony/http-foundation Version ^4.4 || ^5.0.7 || ^6.2
symfony/mime Version ^4.4 || ^5.1 || ^6.2
symfony/process Version ^4.4 || ^5.0.7 || ^6.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ambroisemaupate/intervention-request contains the following files

Loading the files please wait ....