Today I have released my first plugin for the Symfony-Framework. The jsThumbnailPlugin creates Thumbnails on the fly using the GD library. It uses the Symfony cache system to cache the thumbnails.

The plugin consists of a action and a helper. It creates a thumbnail of a image in the given size and stores it in cache for the next calls, until the image changes. You can download it from http://www.symfony-project.org/plugins/jsThumbnailPlugin

The use is very simple:

  1. Install it:

    $ symfony plugin-install http://plugins.symfony-project.com/jsThumbnailPlugin

  2. Enable the module in the setting.yml file of your application:

    all:
      .settings:
         enabled_modules:        [ default, jsThumbnail ]
  3. Now you can view the thumbnail simply by open a link like this:

    http://www.yourhost.com/yourapp.php/jsThumbnail/thumbnail?img=uploads/pictures/image.jpg&maxx=100&maxy=80
  4. The plugin has a helper that creates a image-tag for a thumbnail. Include the helper in your template-file:

    <?php use_helper('Thumbnail') ?>
  5. Call the Helper. The helper needs some params: the imagepath on server, maximum-width and maximum-height. The last parameter are additional HTML compliant tag parameters:

    <?php echo thumbnail_tag('uploads/pictures/image.jpg', 100, 80, array('style'=>'border: 1px solid #ff0000')) ?>
  6. The Plugin automatically checks if the Original image was modificated.

  7. To delete the cached thumbnails call:

    $ symfony cc 

Posted on Nov 04, 2008 Tags: php symfony programmieren