![]() |
|
sfImageTransformPlugin - 0.2.0symfony plugin for manipulating images using the GD or ImageMagick libraries |
|
![]() |
230
users
Sign-in
to change your status |
A simple to use and flexible image manipulation symfony plugin. The plugin allows you to perform "transforms" on an image. A transform maybe simple like a resizing or mirroring or more complex like overlays and pixelizing. The transforms can be chained together or applied individually. New transforms can be simple created by extending the sfImageTranform abstract class. |
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
| Name | Status | |
|---|---|---|
|
|
lead | moc.liamg <<ta>> sewol.trauts |
Copyright (c) 2008 Stuart Lowes
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.
| Version | License | API | Released |
|---|---|---|---|
| 1.4.1stable | MIT license | 1.4.0stable | 17/08/2010 |
| 1.4.0stable | MIT license | 1.4.0stable | 03/05/2010 |
| 1.3.1stable | MIT license | 1.3.0stable | 24/12/2009 |
| 1.3.0stable | MIT license | 1.3.0stable | 01/12/2009 |
| Version | License | API | Released |
|---|---|---|---|
| 1.4.1stable | MIT license | 1.4.0stable | 17/08/2010 |
| 1.4.0stable | MIT license | 1.4.0stable | 03/05/2010 |
| 1.3.1stable | MIT license | 1.3.0stable | 24/12/2009 |
| 1.3.0stable | MIT license | 1.3.0stable | 01/12/2009 |
| Version | License | API | Released |
|---|---|---|---|
| 1.4.1stable | MIT license | 1.4.0stable | 17/08/2010 |
| 1.4.0stable | MIT license | 1.4.0stable | 03/05/2010 |
| 1.3.1stable | MIT license | 1.3.0stable | 24/12/2009 |
| 1.3.0stable | MIT license | 1.3.0stable | 01/12/2009 |
| 1.2.0stable | MIT license | 1.2.0stable | 30/09/2009 |
| 1.1.0stable | MIT license | 1.0.1stable | 11/06/2009 |
| 1.0.1stable | MIT license | 1.0.0stable | 19/03/2009 |
| 1.0.0stable | MIT license | 1.0.0stable | 11/03/2009 |
| 0.2.3beta | MIT license | 0.1.0beta | 28/01/2009 |
| 0.2.2beta | MIT license | 0.1.0beta | 08/01/2009 |
| 0.2.1beta | MIT license | 0.1.0beta | 01/01/2009 |
| Version | License | API | Released |
|---|---|---|---|
| 1.4.1stable | MIT license | 1.4.0stable | 17/08/2010 |
| 1.4.0stable | MIT license | 1.4.0stable | 03/05/2010 |
| 1.3.1stable | MIT license | 1.3.0stable | 24/12/2009 |
| 1.3.0stable | MIT license | 1.3.0stable | 01/12/2009 |
| 1.1.0stable | MIT license | 1.0.1stable | 11/06/2009 |
| 1.0.1stable | MIT license | 1.0.0stable | 19/03/2009 |
| 1.0.0stable | MIT license | 1.0.0stable | 11/03/2009 |
| 0.2.3beta | MIT license | 0.1.0beta | 28/01/2009 |
| 0.2.2beta | MIT license | 0.1.0beta | 08/01/2009 |
| 0.2.1beta | MIT license | 0.1.0beta | 01/01/2009 |
| Version | License | API | Released |
|---|---|---|---|
| 1.4.1stable | MIT license | 1.4.0stable | 17/08/2010 |
| 1.4.0stable | MIT license | 1.4.0stable | 03/05/2010 |
| 1.3.1stable | MIT license | 1.3.0stable | 24/12/2009 |
| 1.3.0stable | MIT license | 1.3.0stable | 01/12/2009 |
| 1.1.0stable | MIT license | 1.0.1stable | 11/06/2009 |
| 1.0.1stable | MIT license | 1.0.0stable | 19/03/2009 |
| 1.0.0stable | MIT license | 1.0.0stable | 11/03/2009 |
| 0.2.3beta | MIT license | 0.1.0beta | 28/01/2009 |
| 0.2.2beta | MIT license | 0.1.0beta | 08/01/2009 |
| 0.2.1beta | MIT license | 0.1.0beta | 01/01/2009 |
| 0.2.0beta | MIT license | 0.1.0beta | 01/01/2009 |
| 0.1.0beta | MIT license | 0.1.0beta | 13/10/2008 |
The sfImageTransformPlugin allows the easily manipulation of images. The plugin requires either either GD or ImageMagick graphics libraries to be installed on the server.
sfImageTransform works by applying one or more "transforms" to the image. A transform maybe simple like resizing or mirroring or more complex like overlays and pixelizing. 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.
Load an image, resize it to 100 pixels wide (preserving the aspect ratio) and rotate it 90 degrees:
$img = new sfImage('image1.jpg', 'image/jpg');
$img->resize(100,null)->rotate(90);
$img->save();
To install the plugin for a symfony project, the usual process is to use the symfony command line:
symfony plugin-install http://plugins.symfony-project.com/sfImageTransformPlugin
Alternatively, if you don't have PEAR installed, you can download the latest package attached to this plugin's wiki page and extract it under your project's plugins/ directory.
Clear the cache to enable the autoloading to find the new classes:
php symfony cc
Note that if you enable MIME detection passing the type are required in the method calls.
Example 1 Chaining
The simplest way to use sfImageTransform is to use method chaining. In an action:
$img = new sfImage('image1.jpg', 'image/jpg');
$response = $this->getResponse();
$response->setContentType($img->getMIMEType());
$response->setContent($img->resize(1000,null)->overlay(sfImage('logo.png')));
return sfView::NONE;
Example 2 Standalone
$img = new sfImage('image1.jpg', 'image/jpg', 'ImageMagick');
$scale = new sfImageScaleImageMagick(0.5);
$img = $scale->execute($img);
$img->saveAs('image2.gif', 'image/gif');
You can override the default settings used by redefining the plugin settings in your project
app.yml
all:
sfImageTransformPlugin:
default_adapter: GD # GD or ImageMagick
default_image: { mime_type: image/png, filename: Untitled.png }
font_dir: /usr/share/fonts/truetype/msttcorefonts
mime_type:
auto_detect: false
library: Fileinfo # Fileinfo (PECL), MIME_Type (PEAR)
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#
Let's create a GD transform called "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);
}
}
Outputting the image using an action
$img = new sfImage('image1.jpg', 'image/jpg');
$img->resize(1000,null)->example($arg1, $arg2);
$response = $this->getResponse();
// Output the right content type
$response->setContentType($img->getMIMEType());
$response->setContent($img);
return sfView::NONE;
Generic
GD
ImageMagick
sfImageTransformPlugin currently supports two MIME type detection libraries, PECL's Fileinfo and PEAR's MIME_Type. These can be installed via PECL and PEAR respectively.
To enable support in the plugin set auto_detect to true and library: Fileinfo # Fileinfo (PECL), MIME_Type (PEAR)
app.yml
... sfImageTransformPlugin: ... mime_type: auto_detect: true library: Fileinfo # Fileinfo (PECL), MIME_Type (PEAR)
With MIME detection enabled there is no need to specific the MIME types in the method calls.
So with MIME detection enable and saving the jpg image to a gif
$img = new sfImage('image1.jpg');
$response = $this->getResponse();
$response->setContentType($img->getMIMEType());
$img->resize(150,null)->overlay(sfImage('logo.png'));
$img->saveAs('image1-with-logo.gif');
return sfView::NONE;
