alexantr/image-resize

Image resizing library

v2.3.0 2022-11-11 14:39 UTC

This package is auto-updated.

Last update: 2024-10-11 18:35:23 UTC


README

Image resizing library. Creates images on demand using GD.

Install

Install through Composer:

composer require alexantr/image-resize

Examples

See full list of examples in example folder.

Creating URLs:

use Alexantr\ImageResize\Image;

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

Can use class member access on instantiation in PHP 5.4 or higher:

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

Creator example

Apache .htacces file:

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

image.php in web root folder:

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

$webroot = __DIR__;
$path = isset($_GET['path']) ? $_GET['path'] : '';

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