Skip to content

Latest commit

 

History

History
70 lines (46 loc) · 2.63 KB

index.rst

File metadata and controls

70 lines (46 loc) · 2.63 KB

Welcome to Imagine's documentation!

Imagine is a OOP library for image manipulation built in PHP 5.3 using the latest best practices and thoughtful design that should allow for decoupled and unit-testable code.

<?php

$imagine = new Imagine\Gd\Imagine();
// or
$imagine = new Imagine\Imagick\Imagine();
// or
$imagine = new Imagine\Gmagick\Imagine();

$size    = new Imagine\Image\Box(40, 40);

$mode    = Imagine\Image\ImageInterface::THUMBNAIL_INSET;
// or
$mode    = Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND;

$imagine->open('/path/to/large_image.jpg')
    ->thumbnail($size, $mode)
    ->save('/path/to/thumbnail.png')
;

Enjoy!

Usage:

.. toctree::
   :maxdepth: 3

   usage/introduction
   usage/coordinates
   usage/drawing
   usage/filters
   usage/exceptions

Api docs:

Find them in the :ref:`genindex`

A couple of words in defense

After reading the documentation and working with the library for a little while, you might be wondering "Why didn't he keep width and height as simple integer parameters in every method that needed those?" or "Why is x and y coordinates are an object called Point?". These are valid questions and concerns, so let me try to explain why:

Type-hints and validation - instead of checking for the validity of width and height (e.g. positive integers, greater than zero) or x, y (e.g. non-negative integers), I decided to move that check into constructor of Box and Point accordingly. That means, that if something passes the type-hint - a valid implementations of BoxInterface or PointInterface, it is already valid.

Utility methods - a lot of functionality, like "determine if a point is inside a given box" or "can this box fit the one we're trying to paste into it" is also to be shared in many places. The fact that these primitives are objects, lets me extract all of that duplication.

Value objects - as you've noticed neither BoxInterface nor PointInterface along with their implementations define any setter. That means the state of those objects is immutable, so there aren't side-effects to happen and the fact that they're passed by reference, will not affect their values.

It's OOP man, come on - nothing to add here, really.

Indices and tables