Download the PHP package domm98cz/image without Composer

On this page you can find all versions of the php package domm98cz/image. 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 image

domm98cz/image

Build Status Latest Version PHP Version

Image manipulation for PHP 8.2+: GD and Imagick behind one immutable, fluent API.

License: MIT.

Install

Requires PHP 8.2 or newer, ext-mbstring, ext-dom and ext-zlib (declared in composer.json, present in most default PHP installs), and ext-gd and/or ext-imagick. Both image extensions are optional on their own: GD alone or Imagick alone runs the whole API, and with both installed each step runs on whichever driver does it better (see Drivers for what differs). psr/http-message and psr/http-factory are interface-only dependencies - any PSR-17 implementation works for output, e.g. nyholm/psr7 or guzzlehttp/psr7. Optional: the pngquant, jpegtran, cwebp and gifsicle binaries, for the matching Optimization\External\* adapters.

Quick start

Every fluent call returns a new builder and nothing is decoded until a terminal call. Input is still validated at open*(), so a hostile or broken file fails there, not later at save(). Runnable scripts for every feature below are in examples/; each one generates its own input, so no image file is needed.

Opening images

Applications should create one configured ImageFactory (it is DI-friendly). The static ImageBuilder::open*() shortcuts use the default configuration.

HEIC/HEIF (the format iPhones save photos as) is decode-only and Imagick-only: GD has no HEIC codec at all, and this library never writes HEIC (no encoder is registered, for the same patent/licensing reasons most web tooling re-encodes it to WebP or AVIF instead). EXIF orientation and embedded metadata are not read yet for HEIC - autoOrient() is a no-op on it, same as today's AVIF.

Operations

Call Does
resize(Dimensions, Interpolation $interpolation = Interpolation::Lanczos) exact size (aspect ratio not kept)
scale(float), scaleToWidth(int), scaleToHeight(int) proportional scaling, each takes the same Interpolation
fitInside(Dimensions, upscale: false) largest size that fits in the box
fitOutside(Dimensions, upscale: false) smallest size that covers the box
thumbnail(Dimensions, Anchor, upscale: true) cover and crop to exactly that size
crop(Rectangle), cropAnchored(Dimensions, Anchor) cut out a region
pad(int $left, int $top, int $right, int $bottom, ?Color), extend(...) grow the canvas, filling with a background color (transparent by default)
border(int $size, ?Color) pad() with the same size on all four sides
trim() remove a uniform-colored outer border
paste(Image, Point, float $opacity = 1.0, BlendMode), insert(...) composite another image at a position
rotate(Angle, ?Color $background), flip(FlipDirection), autoOrient() orientation (angles are clockwise)
grayscale(), invert(), brightness(int), contrast(int), gamma(float) adjustments
blur(float $sigma), sharpen(float), colorize(Color, float) filters
opacity(float), sepia(), hueSaturation(float $hue, float $saturation), pixelate(int $size) more filters, over the whole image
roundedCorners(int $radius), mask(Image) clear or multiply the alpha channel
draw(Canvas\|Closure) shapes and text (below)
applyPixels(PixelFilterInterface\|Closure, ?Rectangle) your own filter over a PixelBuffer
watermark(WatermarkInterface) visible, steganographic or metadata watermark
apply(OperationInterface) any operation value, including your own

Operations are plain immutable values (new Resize(...), new Blur(...)), so they can be stored and reused with applyAll().

Interpolation (Nearest, Bilinear, Bicubic, Lanczos) picks the resampling filter for every resize-family call. Imagick maps it 1:1 to Imagick::FILTER_*; GD only distinguishes Nearest (imagecopyresized) from everything else (imagecopyresampled), so Bilinear/Bicubic/Lanczos render identically on GD.

trim()'s output size depends on pixel content, so the planner cannot forecast it: resultingDimensions() conservatively reports the input size unchanged, which only affects cost estimation for steps chained after trim(), never correctness.

Output

Some details:

Optimization and the smallest encoding

Optimizers run after encoding and before metadata watermarks, so they cannot strip the watermark. Every Optimization\External\* adapter follows the same rules: an argument vector run without a shell, a timeout, an output-size cap, and re-validation of the tool's output (format, dimensions, and for GifsicleOptimizer frame count) before trusting it - the external binary is treated as untrusted, same as any other input. All of them keep the original bytes if the tool's result is not smaller.

Pixels, drawing and text

Characters the font has no glyph for are drawn as U+FFFD (the replacement character, or ? when the font lacks that too) on every driver, so text looks the same whichever driver renders it. Text is always drawn literally: & stays &. GD cannot reach glyphs beyond the Basic Multilingual Plane (emoji, historic scripts) even when the font has them, so it draws the same placeholder there while Imagick draws the glyph. Lines separated by "\n" are stacked 1.2 em apart (1.2 x Font::$size, rotated along with the text) on every driver; for another line pitch draw each line with its own text() call.

Analysis

Read-only queries over the decoded pixels, never touched by any driver-specific handler:

dominantColor()/palette() use median-cut, splitting the widest-range channel at its population median; a solid-color image always yields exactly one cluster. blurhash() follows the standard blurhash.org algorithm (alpha is not part of that format). perceptualHash() is a difference hash: robust to recompression and minor resizing, not to rotation or cropping.

Animations

GIF works on any driver; animated WebP needs Imagick. The same fluent operations apply to every frame.

Animation builders offer the same terminal calls as images: encode, encodeSmallest, save, toStream, toResponse and toDataUri, and accept stored operations through applyAll() just like image builders. Unlike ImageBuilder, openAnimation*() decodes every frame at open time; only the operations are deferred.

Watermarks

All three watermark kinds use the same ->watermark() call:

Drivers

ext-gd and ext-imagick are both optional, and either one alone runs the library: the API, the planner and every pure-PHP part (GIF container, metadata, steganography, analysis) are the same on both; what differs is listed in the table below. Install both and the planner uses them together. For every step it compares what each installed driver offers - Native, PhpFallback, Degraded or None - against the cost of moving pixels between drivers, and picks the cheapest route. Nothing needs configuring: a missing extension is simply not a candidate.

GD vs. Imagick

Each row is what the driver reports to the planner. Imagick probes its ImageMagick build once per process wherever builds are known to differ, so the same code answers differently on ImageMagick 6 and 7.

GD Imagick
JPEG, PNG, GIF, WebP (still images) Native, per libgd build (imagetypes()) Native, per ImageMagick coder
AVIF Native when libgd is built with libavif Native on ImageMagick 7; Degraded on ImageMagick 6 (Debian bookworm: wrong colors on decode, alpha dropped on encode)
HEIC/HEIF input None Native when the HEIC coder is present; decode only, no driver writes HEIC
Animated GIF Native (pure-PHP container, frames decoded by the driver) Native
Animated WebP None Native on ImageMagick 7; None on ImageMagick 6
Embedded ICC profile to sRGB Degraded: the profile is ignored, so wide-gamut photos look muted and CMYK is wrong Native when ImageMagick is built with lcms, Degraded otherwise
Resize filters Nearest or one resampled path (Bilinear, Bicubic, Lanczos render identically) 1:1 Imagick::FILTER_*
Drawing Degraded: only hairlines are anti-aliased, thick strokes and filled shapes have jagged edges Native anti-aliasing
Text outside the Basic Multilingual Plane (emoji) placeholder glyph drawn
Blend modes Normal native; the other separable modes run the PHP compositor over the overlay's area Native operators, each probed once against the W3C formula; modes ImageMagick computes differently fall back to the PHP compositor
trim() PhpFallback (per-pixel scan) Native
Pixel buffer steps: applyPixels(), steganographic watermarks, blend fallback PhpFallback: no bulk export, reads are an imagecolorat() loop (about 1.1 s per 12 MP), writes go through a stored PNG Native: raw RGBA blob both ways
Alpha channel precision 7-bit (128 levels): the lowest bit of an 8-bit alpha is lost full 8-bit
Geometry, color adjustments, filters, composite, pad Native Native
autoOrient(), metadata watermarks and stripping, analysis pure PHP, identical pure PHP, identical

GD's 7-bit alpha is also why both steganographic watermarks embed only in R, G and B of opaque pixels on every driver: an alpha LSB would not survive a GD round trip, so it is never used, and capacity is the same on both.

With both drivers installed the practical outcome is: Imagick decodes anything carrying a wide-gamut or CMYK profile, HEIC and animated WebP, and renders drawing, trim() and buffer steps; GD keeps the steps it does natively (ties stay on the driver already holding the image, then registry order, GD first). A hand-off is a lossless PNG that costs about as much as one PHP pass, so the planner moves an image for a Degraded or None step, or when several fallback steps cluster, not to save a single one.

Force a driver, for example for debugging, with Configuration::default()->withForcedDriver(DriverName::Gd).

The prices the planner compares are relative nanoseconds per pixel, fitted to a CPU-only build of GD and ImageMagick 7. A machine whose drivers perform differently, say a GPU-accelerated ImageMagick where native steps and the PNG hand-off between drivers are far cheaper than a PHP pass, can hand in its own measurements:

Only the ratios matter; degradedNanosPerPixel stays far above the rest so a lossless path still wins whenever one exists. The constructor enforces that much: every cost must be a non-negative number (zero is allowed) and degradedNanosPerPixel must exceed the other three, otherwise it throws InvalidConfigurationException.

Security

Limits default
maxWidth / maxHeight 16 384 px
maxPixels 50 MP
maxFrames 500
maxAnimationPixels 200 MP (all frames together)
maxInputBytes 50 MB
checkMemoryLimit on

Exceptions

Everything the library throws implements Domm98CZ\Image\Exception\ImageException. The abstract categories are:

Contributing / running tests

Everything runs in Docker (Debian trixie with PHP 8.4 and ImageMagick 7):

Script Runs
composer test unit suite (fake driver, no extensions needed)
composer test:integration integration suite (real ext-gd / ext-imagick)
composer phpstan PHPStan, level max + strict rules, src/ only
composer cs / composer cs:fix PHP-CS-Fixer, PER-CS 2.0

The library supports PHP 8.2 through 8.5; the development image pins PHP 8.4.


All versions of image with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2 <8.6
ext-ctype Version *
ext-dom Version *
ext-mbstring Version *
ext-zlib Version *
psr/http-factory Version ^1.1
psr/http-message Version ^2.0
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 domm98cz/image contains the following files

Loading the files please wait ...