thapp/image

Image processor

v1.0.0beta1 2015-01-29 16:39 UTC

This package is not auto-updated.

Last update: 2024-04-13 13:56:49 UTC


README

Build Status Code Climate Coverage Status HHVM Status Latest Stable Version Latest Unstable Version License

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.

Installation

Require thapp/image in your project directory

$ composer require thapp/image

or add this to your composer.json

{
	"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:

<?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.

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.

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).

<?php

use Thapp\Image\Info\ExifReader;
use Thapp\Image\Driver\Imagick\Source;

$source = new Source(new ExifReader);

// ...

$image = $source->load('image.jpg');