Download the PHP package zenstruck/image without Composer
On this page you can find all versions of the php package zenstruck/image. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zenstruck/image
More information about zenstruck/image
Files in zenstruck/image
Package image
Short Description Image file wrapper with generic transformation support.
License MIT
Homepage https://github.com/zenstruck/image
Informations about the package image
zenstruck/image
Image file wrapper to provide image-specific transformations, and ThumbHash generator.
Installation
Usage
[!NOTE]
Zenstruck\ImageFileInfo
extends\SplFileInfo
.[!NOTE] Images created with
ImageFileInfo::from()
are created in unique temporary files and deleted at the end of the script.
Transformations
The following transformers are available:
To use the desired transformer, type-hint the first parameter of the callable
passed to Zenstruck\ImageFileInfo::transform()
with the desired transformer's
image object:
- GD:
\GdImage
- Imagick:
\Imagick
- intervention\image:
Intervention\Image\Image
- imagine\imagine:
Imagine\Image\ImageInterface
- spatie\image:
Spatie\Image\Image
[!NOTE] The return value of the callable must be the same as the passed parameter.
The following example uses \GdImage
but any of the above type-hints can be used.
Transform "In Place"
Filter Objects
Both Imagine and Intervention have the concept of filters. These are objects
that can be passed directly to transform()
and transformInPlace()
:
Custom Filter Objects
Because transform()
and transformInPlace()
accept any callable, you can wrap complex
transformations into invokable filter objects:
To use, pass a new instance to transform()
or transformInPlace()
:
Transformation Object
Zenstruck\ImageFileInfo::as()
returns a new instance of the desired
transformation library's image object:
ThumbHash
A very compact representation of an image placeholder. Store it inline with your data and show it while the real image is loading for a smoother loading experience.
[!NOTE]
srwiez/thumbhash
is required for this feature (install withcomposer require srwiez/thumbhash
).[!NOTE]
Imagick
is required for this feature.
Generate from Image
[!CAUTION] Generating from an image can be slow depending on the size of the source image. It is recommended to cache the data-uri and/or key for subsequent requests of the same ThumbHash image.
Generate from Key
When generating from an image, the ThumbHash::key()
method returns a small string that
can be stored for later use. This key can be used to generate the ThumbHash without
needing to re-process the image.