Download the PHP package middlewares/image-manipulation without Composer
On this page you can find all versions of the php package middlewares/image-manipulation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download middlewares/image-manipulation
More information about middlewares/image-manipulation
Files in middlewares/image-manipulation
Package image-manipulation
Short Description Middleware to manipulate images on-demand
License MIT
Homepage https://github.com/middlewares/image-manipulation
Informations about the package image-manipulation
middlewares/image-manipulation
Middleware to transform images on demand, allowing resize, crop, rotate and transform to other formats. Uses imagecow library that can detect and use Gd
and Imagick
, and also has support for client hints and different automatic cropping methods.
The uri is generated encoding the image path and the manipulation options with lcobucci/jwt, to prevent alterations and image-resize attacks.
Note: To keep the SRP, this middleware does not provide the following functionalities, that should be delegated to other middleware:
-
Read the image from a directory: this library just manipulate the image response returned by inner middlewares, does NOT read in the filesystem.
- Image caching: The library returns a response with the manipulated image but does NOT provide any caching system.
It's possible to combine this library with middlewares/filesystem that allows to read and write to the filesystem. (See example below).
Requirements
- PHP >= 7.2
- A PSR-7 http library
- A PSR-15 middleware dispatcher
Installation
This package is installable and autoloadable via Composer as middlewares/image-manipulation.
Example
The following example uses also middlewares/filesystem to read/save the manipulated images.
Usage
You need a key to sign the uri. This prevent attacks and alterations to the path.
Optionally, you can provide a Psr\Http\Message\StreamFactoryInterface
as the second argument to create the new response stream with the image. If it's not defined, Middleware\Utils\Factory will be used to detect it automatically.
clientHints
This option allows to use client hints, that is disabled by default. If this method is called with the default arguments, the allowed hints are ['Dpr', 'Viewport-Width', 'Width']
. Note that client hints are supported only by Chrome and Opera browsers
library
The library to use. It can be Gd
or Imagick
. It's autodetected if it's not specified.
Helpers
getUri
To ease the uri creation this static method is provided, accepting three arguments:
$image
: The image path. This value is used to replace the uri's path of the request to the next middlewares.$transform
: The transformation details. You can use any method of imagecow api as a string, for example:resize,200
: Resize the image to 200px width (automatic height)crop,200,500
: Crop the image to 200x500px (centered)crop,100,100,CROP_ENTROPY
: Crop the image to 100x100px using the entropy method to find the most interesting point of the imageresize,300|rotate,90|format,jpg
: Resize the image to 300px width, rotate 90º and convert to jpg
$signatureKey
: Optional signature key to sign the uri path. If it's not provided, use the same key passed to the middleware.
Please see CONTRIBUTING for contributing details.
The MIT License (MIT). Please see LICENSE for more information.
All versions of image-manipulation with dependencies
imagecow/imagecow Version ^2.1
lcobucci/jwt Version ^3.2
middlewares/utils Version ^3.0
psr/http-server-middleware Version ^1.0