Image resizing library. Creates images on demand using GD.
Install through Composer:
composer require alexantr/image-resize
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="">
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);