xicrow/php-image

PHP image manipulation

1.0.0 2022-09-09 17:36 UTC

This package is not auto-updated.

Last update: 2024-11-03 02:05:14 UTC


README

PHP image manipulation

Packagist Latest Stable Version Packagist Total Downloads

Installation

The recommended way to install is through Composer.

composer require xicrow/php-image
{
	"require": {
		"xicrow/php-image": "~1.0"
	}
}

Usage

The idea is to build up a list of actions to perform on an image, and then saving the processed image.

Simple example, resize a given image to 500x500px and convert it to greyscale:

use Xicrow\PhpImage\Image\Action\FilterGreyScale;
use Xicrow\PhpImage\Image\Action\ResizeCrop;
use Xicrow\PhpImage\Image\Adapter\GDLibrary;

$strImagePath = '/path/to/image.jpg';
$oAdapter     = new GDLibrary($strImagePath);
$oAdapter->addAction(new ResizeCrop(500, 500));
$oAdapter->addAction(new FilterGreyScale());
$oAdapter->save('/path/to/converted/image.jpg');

Slightly more advanced example, resize a given image to 500x500px, adjust colors, adjust contrast and draw some lines:

use Xicrow\PhpImage\Image\Action\DrawLine;
use Xicrow\PhpImage\Image\Action\FilterColorize;
use Xicrow\PhpImage\Image\Action\FilterContrast;
use Xicrow\PhpImage\Image\Action\ResizeCrop;
use Xicrow\PhpImage\Image\Adapter\GDLibrary;

$strImagePath = '/path/to/image.jpg';
$oAdapter     = new GDLibrary($strImagePath);
$oAdapter->addAction(new ResizeCrop(500, 500));
$oAdapter->addAction(new FilterColorize(10, 25, 10));
$oAdapter->addAction(new FilterContrast(15));
$oAdapter->addAction(new DrawLine(25, 0, 25, 500));
$oAdapter->addAction(new DrawLine(475, 0, 475, 500));
$oAdapter->save('/path/to/converted/image.jpg');

Example

See examples in the demo folder

TODO

  • PHPUnit tests

License

Copyright © 2022 Jan Ebsen Licensed under the MIT license.