alexantr/image-resize

Image resizing library

Maintainers

Package info

github.com/alexantr/image-resize

pkg:composer/alexantr/image-resize

Statistics

Installs: 1 312

Dependents: 0

Suggesters: 0

Stars: 4

v3.0.0 2026-06-07 00:13 UTC

This package is auto-updated.

Last update: 2026-06-07 13:58:08 UTC


README

Image resizing library. Creates images on demand using GD or Imagick if installed.

Install

Install through Composer:

composer require alexantr/image-resize

Examples

Generate URL to resized image:

use Alexantr\ImageResize\Image;

$src1 = (new Image('uploads/pic.jpg'))->crop(200, 200);
$src2 = (new Image('uploads/pic.jpg'))->silhouette()->quality(95)->fit(200, 200);
$src3 = (new Image('uploads/pic.jpg'))->fitWidth(200);
$src4 = (new Image('uploads/pic.jpg'))->fitHeight(200);
$src5 = (new Image('/site/uploads/pic.jpg'))->bgColor('6af')->fill(200, 200);

Or with init() static method:

<img src="<?= Image::init('uploads/pic.jpg')->crop(200, 200) ?>" alt="">

More examples in example folder.

Configure Creator

Apache .htaccess example:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^resized/(.+)$ image.php?path=$1 [L,QSA]

nginx config example:

location ~ ^/resized/(.+)$ {
    try_files $uri $uri/ /image.php?path=$1&$args;
}

Example of image.php:

require '../vendor/autoload.php';

$webroot = __DIR__;
$path = $_GET['path'] ?? '';

// custom defaults
//Alexantr\ImageResize\Creator::$defaultQuality = 70;
//Alexantr\ImageResize\Creator::$enableProgressiveJpeg = true;
//Alexantr\ImageResize\Creator::$imagickDisabled = true;

Alexantr\ImageResize\Creator::create($webroot, $path);