Thumbnail Generation In Symfony Using jsThumbnailPlugin
anoopsachari | Apr 13, 2010 | Comments 2
Trying to generate thumbnail in symfony ? well there is a great plugin named jsThumbnailPlugin that would help you to do the same .
The plugin create the thumbnails using GD library and uses the symfony cache system to cache the thumbnails . Its simple to configure and use .
Step 1 : download the jsThumbnailPlugin from http://plugins.symfony-project.com/jsThumbnailPlugin .
Step 2 : extract the above package to plugins folder
Step 3 : usage code
public function executeUploadpic()
{
$fileName = $this->getRequest()->getFileName('file');
if($fileName != '')
{
$this->getRequest()->moveFile('file', sfConfig::get('sf_upload_dir').'/images/user/'.$fileName);
$name = sfConfig::get('sf_upload_dir').'/images/user/'.$fileName;
$img = new sfImage($name, 'image/jpg');
$img->thumbnail(150,150);
$img->setQuality(50);
$tmp_fileName = 'tn_'.$fileName;
$tn_fileName = sfConfig::get('sf_upload_dir').'/thumbs/userimage/'.$tmp_fileName;
$img->saveAs($tn_fileName);
$flag = 1;
}
}
$img->thumbnail(150,150); – specify the width and height of the thumbnail to be generated .
$img->setQuality(50); – specify the quality of the thumbnail .
Hope it helped you !
public function executeUploadpic()
{
$fileName = $this->getRequest()->getFileName(‘file’);
if($fileName != ”)
{
$this->getRequest()->moveFile(‘file’, sfConfig::get(‘sf_upload_dir’).’/images/user/’.$fileName);
$name = sfConfig::get(‘sf_upload_dir’).’/images/user/’.$fileName;
$img = new sfImage($name, ‘image/jpg’);
$img->thumbnail(150,150);
$img->setQuality(50);
$tmp_fileName = ‘tn_’.$fileName;
$tn_fileName = sfConfig::get(‘sf_upload_dir’).’/thumbs/userimage/’.$tmp_fileName;
$img->saveAs($tn_fileName);
$flag = 1;
}
}
Filed Under: symfony
About the Author: a holistic web developer , movie buff and technical blogger from queen of arabian sea.







Thank you. Great website you got here. Have some more sites to direct to with more stuff like this?
For Symfony 1.4 (starting with 1.2) you will have to enable this plugin through the /config/ProjectConfiguration.class.php
$this->enablePlugins(array(‘sfDoctrinePlugin’, ‘jsThumbnailPlugin’));