wdsSfThumbnailAddonPlugin - 1.2.0

WDS sfThumbnail addon plugin.

You are currently browsing
the website for symfony 1

Visit the Symfony2 website

« Back to the Plugins Home


Forgot your password?
Create an account



advanced search
Information Readme Dependencies Releases Changelog Contribute
Show source

wdsSfThumbnailAddonPlugin plugin

Extension to the sfThumbnail plugin. Now you can easily add photo thumbnails generation to your model.


You can install using the plugin-install task:

php symfony plugin-install wdsSfThumbnailAddonPlugin

You can also pull the code directly from the Subversion repository using a svn checkout or the svn:externals property on your project's /plugins directory.

Configuring the plugin

You can configure the plugin via app.yml (the example below configures the plugin to generate two thumbnails with sfPropelBehavior turned off).

    sfPropelBehaviorEnabled:  false
    quality:  75
    crop:     false
        size:     50x50
        path:     thumbnails_50
        crop:     true
        size:     100x100
        path:     thumbnails_100
        quality:  90

You must add the plugin interface to your model classes (as it is done in the example below).

class Photo extends BasePhoto implements PhotoThumbnail
    public function getPhotoFileName()
        return $this->getPhotoFileName();

    public function getPhotoSizes()
        return array();

The PhotoThumbnail interface uses two methods for thumbnail generation:

  • getPhotoFileName() - this method should return the original photo filename

    return $this->getPhotoFileName();
  • getPhotoSizes() - you can define here an array of thumbnail sizes that you want to create for the model

    return array('PHOTO_THUMBNAIL_50');  // this tells the plugin to generate only this thumbnail size

Using the plugin with Propel model

When you use Propel ORM, you can use sfPropelBehavior to automate thumbnail generation/removal for your model class (you have to enable it first in app.yml):

    sfPropelBehaviorEnabled:  true

sfPropelBehavior::add('Photo', array('Thumbnailable'));

Using the plugin with Doctrine model

When you use Doctrine ORM, you can use two methods instead of sfPropelBehavior to automate thumbnail generation/removal for your model class:

public function postSave($event)

public function preDelete($event)

From version 1.1.0 there is also a behavior available. You can use it instaead of defining the above two methods in every model class that uses thumbnails.

    Thumbnailable: ~

Auto-removing of original file when removing thumbnails

If you want to remove original file when the thumbnail are removed, it can be done dy adding code below to your model class:

public function removeOriginalPhoto()
    return true;

Using thumbnail_image_tag helper in the template

<?php use_helper('ThumbnailAddon'); ?>

<?php echo thumbnail_image_tag($photo, array(
                                         'thumbnail_constant'    => 'PHOTO_THUMBNAIL_100', 
                                         'auto_include_filename' => true
                                       )); ?>


Version 1.2.0

  • Changed ThumbnailGeneretor to Thumbnailable (Doctrine behavior)
  • Added Propel behavior (Thumbnailable)
  • Small changes to app.yml.dist
  • Added ability to turn off Propel behavior (default off)
  • Added support for models that have optional photo filename field

Version 1.1.0

  • Added image quality and crop support (requires ImageMagick)
  • Moved app.yml to app.yml.dist (added svn:ignore for app.yml)
  • Fixed thumbnail removal
  • Fixed photoThumbnailSupport::getThumbnailPath support for Doctrine
  • Added Doctrine behavior to automate thumbnail support
  • Added logging support
  • Updated README

Version 1.0.1

  • Fixed thumbnail removal
  • Fixed photoThumbnailSupport::getThumbnailPath support for Doctrine
  • Added ability to remove the original file with the thumbanils
  • Updated README

Version 1.0.0

  • Initial public release.


Sebastian Owodziń