Search by

adachsoft / image-reader-lib

Arkadiusz Adach

GD-based image reader with magic-byte format detection, size limits, and proportional downscaling.

Package info

gitlab.com/a.adach/image-reader-lib

Issues

pkg:composer/adachsoft/image-reader-lib

Statistics

Installs: 30

Dependents: 3

Suggesters: 0

Stars: 0

v0.1.0 2026-11-28 00:11 UTC

This package is auto-updated.

Last update: 2026-11-27 23:14:05 UTC


README

Purpose

This package implements the image-reader contracts with PHP GD. It detects PNG, JPEG, GIF, and WebP from magic bytes, enforces encoded input/output byte limits and a decoded-pixel limit before GD decoding (50,000,000 pixels by default), and proportionally resizes images while retaining their format and supported transparency.

Animated GIF input is decoded and re-encoded as its first frame.

Requirements

The package requires PHP with the GD extension enabled. Composer installs the image-reader contracts dependency.

Installation

Install the library with Composer:

composer require adachsoft/image-reader-lib

PHP GD must be enabled in the PHP runtime that uses the package.

Usage

Integration

Create a GdImageReader and pass the encoded image bytes together with an ImagePrepareOptionsDto from the contracts package. The reader returns a PreparedImageDto containing the prepared bytes, detected format, resulting dimensions, and original-image metadata. Catch the image-reader contract exceptions to handle invalid, unsupported, or oversized input.

API

use AdachSoft\ImageReaderContracts\ImagePrepareOptionsDto;
use AdachSoft\ImageReaderLib\GdImageReader;

$reader = new GdImageReader();
$options = new ImagePrepareOptionsDto(
    maxDimension: 2048,
    maxInputBytes: 10_000_000,
    maxOutputBytes: 2_000_000,
    maxInputPixels: 50_000_000,
);

$prepared = $reader->prepare($imageBytes, $options);