Image processing
, (*1)
This module was created for the usage in Thapp\JitImage, but can be used as
a standalone library for manipulating images. It's highly inspired by the Imagine
library, but resolves a views flaws, but also way more limited., (*2)
Installation
Require thapp/image
in your project directory, (*3)
$ composer require thapp/image
or add this to your composer.json
, (*4)
{
"require": {
"thapp/image": "dev-master"
}
}
Usage
Quick Example
<?php
use Thapp\Image\Geometry\Size;
use Thapp\Image\Driver\Imagick\Source;
$source = new Source;
$image = $source->load('image.jpg');
$image->edit()->crop(new Size(100, 100));
$image->save('newimage.jpg');
Loading sources
The Source
object is able to create Image
instances from either filepaths,
filehandles, or binary strings:, (*5)
<?php
use Thapp\Image\Driver\Imagick\Source;
$source = new Source;
$image = $source->load('image.jpg');
// or read the file from a file handle:
$handle = fopen('image.jpg', 'r+');
$image = $source->read($handle);
// or read the file from a binary string:
$content = file_get_contents('image.jpg');
$image = $source->create($content);
The Source
class takes an instance of
Thapp\Image\Info\MetaDataReaderInterface
as its first argument. The $reader
is used to read meta information about the image. This is useful e.g. if you
want to autorotate the image based on its orientation., (*6)
By default, a new instance of Thapp\Image\Info\ImageReader
is created for
you. ImageReader
is capable of reading basic image information derived from
the php getimagesize()
function., (*7)
You may use the Thapp\Image\Info\ImageReader
class instead, which provides
a wider range of information (e.g. needed for GD
and Gmagick
drivers to
determine the correct image orientation)., (*8)
<?php
use Thapp\Image\Info\ExifReader;
use Thapp\Image\Driver\Imagick\Source;
$source = new Source(new ExifReader);
// ...
$image = $source->load('image.jpg');