Search by

adachsoft / image-editor-lib

Arkadiusz Adach

GD-based PHP image editor for cropping, resizing, rotating, flipping, filters, text, and shapes.

Package info

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

Issues

pkg:composer/adachsoft/image-editor-lib

Statistics

Installs: 26

Dependents: 1

Suggesters: 0

Stars: 0

v0.2.0 2026-11-29 16:48 UTC

This package is auto-updated.

Last update: 2026-11-29 15:48:59 UTC


README

Purpose

This package implements the image-editor contracts with PHP GD. It accepts encoded image bytes or canvas settings, applies ordered image operations, enforces configured byte and pixel limits, and returns encoded image bytes. Supported formats are PNG, JPEG, GIF, and WebP.

The library uses the public ImageFormatDetector from the image-reader library to identify input formats from magic bytes. Source dimensions and input pixel limits are checked before decoding. PNG, WebP, and GIF output retain transparency where the target format supports it; JPEG output is flattened onto white.

Text drawing uses the bundled DejaVu Sans font and supports UTF-8 text, including Polish characters.

Installation

Install the library with Composer:

composer require adachsoft/image-editor-lib

PHP GD must be enabled. Composer installs the image editor contracts and image reader dependencies required by the library.

Integration

Create a GdImageEditor instance, build an ImageEditRequestDto with encoded source bytes, the requested operations and output settings, then call edit(). The returned EditedImageDto contains the encoded result. See the usage example for a complete integration snippet.

Requirements

  • PHP 8.3 or later
  • PHP GD extension

Usage

Pass encoded image bytes and an ordered collection of operations to the editor, then use the returned encoded bytes in your application. The complete request example is shown in the API section below and in Basic Usage.

API

use AdachSoft\ImageEditorContracts\ImageEditLimitsDto;
use AdachSoft\ImageEditorContracts\ImageEditRequestDto;
use AdachSoft\ImageEditorContracts\ImageOperationCollection;
use AdachSoft\ImageEditorLib\GdImageEditor;
use AdachSoft\ImageReaderContracts\ImageFormatEnum;

$editor = new GdImageEditor();
$result = $editor->edit(new ImageEditRequestDto(
    sourceBytes: $imageBytes,
    canvas: null,
    operations: new ImageOperationCollection([]),
    outputFormat: ImageFormatEnum::Png,
    limits: new ImageEditLimitsDto(10_000_000, 50_000_000, 50_000_000, 20, 2_000, 5_000_000),
));

Brand and social image operations

Add a logo watermark

Place a logo in the bottom-right corner of a photo, sized to 15% of its width, with a soft black shadow:

use AdachSoft\ImageEditorContracts\AnchorEnum;
use AdachSoft\ImageEditorContracts\ImageOperationCollection;
use AdachSoft\ImageEditorContracts\Operation\OverlayImageOperationDto;
use AdachSoft\ImageEditorContracts\ShadowDto;

$watermark = new OverlayImageOperationDto(
    imageBytes: $logoPngBytes,
    anchor: AnchorEnum::BOTTOM_RIGHT,
    marginX: 24,
    marginY: 24,
    widthPercent: 15.0,
    shadow: new ShadowDto(offsetX: 1, offsetY: 2, blur: 8, opacity: 35),
);

$operations = new ImageOperationCollection([$watermark]);

Create a 1000×1500 Pinterest pin from a 16:9 photo

Keep the full landscape photo visible on a portrait pin and fill the remaining space with its blurred, cover-scaled background:

use AdachSoft\ImageEditorContracts\FitModeEnum;
use AdachSoft\ImageEditorContracts\ImageOperationCollection;
use AdachSoft\ImageEditorContracts\Operation\FitOperationDto;

$pin = new FitOperationDto(
    width: 1000,
    height: 1500,
    mode: FitModeEnum::CONTAIN_BLURRED_BACKGROUND,
    blurStrength: 12,
);

$operations = new ImageOperationCollection([$pin]);