A simple to use and flexible image manipulation symfony plugin. The plugin allows you to perform "transforms" on an image. A transform can be simple like thumbnailing, resizing or mirroring or more complex such as adding watermarks and pixelizing. The transforms can be chained together or applied individually. New transforms can be simply created by extending the sfImageTranform abstract class. GD and ImageMagick are both suppported

Developers

License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Release 0.2.0 - 01/01/2009

Release 0.1.0 - 13/10/2008

Image manipulation made easy - sfImageTransformPlugin

Introduction

The aim of sfImageTransformPlugin is take the pain out of image manipulating in PHP/symfony. sfImageTransformPlugin is great for but not limited to common tasks like creating thumbnails, adding text to dynamic images or watermarking.

sfImageTransformPlugin works by applying one or more "transform" to the image. A transform maybe a simple action like resize or thumnnail, mirror or more complex like an overlay (watermarks) and pixelize.

Multiple tranforms can be easily applied by chaining the transform calls as seen below. It is also very easy to extend and create your own transforms, see "Writing your own transforms" for an example.

Example 1. Simple chaining of transforms

Load an image, resize it to 100 pixels wide (preserving the aspect ratio) and add some text

Note: If you install one of the supported MIME detection libraries you do not have to pass in the image's MIME type. See the section "Enabling MIME detection" for details.

Included tranforms

sfImageTransform comes bundled with many transforms, which are listed below. The plugin has full phpdoc style API documentation, including all the available transforms. This can be generated using phpDocumentor

Once phpDocumentor is installed you can generate the docs from inside the plugin's directory as follows,

phpdoc -o HTML:frames:DOM/phphtmllib -d . -t docs

Generic

border

callback

resize

thumbnail

GD

alphaMask, arc

brightness

colorize, contrast, crop

edgeDetect, ellipse, emboss

fill, flip

gamma, gaussianBlur, greyscale

line

mirror

negate, noise

opacity, overlay

pixelBlur, pixelize

rectangle, rotate, roundedCorners

scale, scatter, selectiveBlur, sketchy, smooth

text, transparency

ImageMagick

brightness

colorize, crop

fill, flip

greyscale

line

mirror

opacity, overlay

prettyThumbnail

rectangle, rotate

scale

text, trim

Writing your own transforms

sfImageTransformPlugin is designed to be easily extended. To make a new transform you simple create a class that extends the abstract class (sfImageTransformAbstract) and implements the transform method.

Transforms are written specifically for the image library you want to use or generically if they don't use image library specific calls (see the thumbnail transform).

The naming convention for a transform is important. For generic transforms the class should be named sfImage#transform name#Generic and for graphic library specific transforms, sfImage#transform name##image library#.class.php and class names should be sfImage#transform name##image library#

Example 6. Creating a new GD transform, "Example"

sfImageExampleGD.class.php

class sfImageExampleGD extends sfImageTransformAbstract
{
// Parameters can be passed in the standard way
public funnction __construct($arg1, $arg2)
{
...
}
public function execute(sfImage $image)
{
// Get the actual image resource
$resource = $image->getAdapter()->getHolder();
// Manipulate image using the GD functions
...
// To set a new resource for the image object
$image->getAdapter()->setHolder($dest_resource);
}
}