Symfony sfAssetsLibraryPlugin assets resize script

Hi there!

I’d like to share with this pretty simple script with you, hope it will save you few minutes.

You guys who familiar with this Symfony plugin for assets management probably know that it uses sfThumbnail plugin for making thumbnails of image assets.
sfThumbnail has configuration in app.yml and it looks like:

This is cool but when you have your project up and running and decided to add new type of thumbnail (for instance name it ‘big’)

you’ll have a problem: you need to resize all old images according to new thumbnail type.

“This is simple science” – you need to get all assets objects and resize them in the following way:
1. Create batch script in you symfony batch folder:

Also make sure that it users ‘backend’ application (or application that uses sfAssetAdmin module)

2. Place content from the following code block into your batch script

3. Run it

Important notice: if you have a lot of image assets (thousands) you need to refine this script using object hydration.
I’ll do it later, just to let you know.
Peace! 🙂

  • KSN135

    redesigned as task… 🙂


    // new sfCommandArgument('my_arg', sfCommandArgument::REQUIRED, 'My argument'),

    // ));


    new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name'),

    new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),

    new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),

    // add your own options here


    $this->namespace = 'asset';

    $this->name = 'regenerate-thumbnails';

    $this->briefDescription = 'Regenerate all thumbnals using parameters defined in app.yml';

    $this->detailedDescription = <<configuration);

    $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();

    // If you have a lot of records you should refine this using hydration

    $c = new Criteria();

    $c->add(sfAssetPeer::TYPE, 'image');

    $assets = sfAssetPeer::doSelect($c);

    foreach ($assets as $asset) {

    echo 'Processing ' . SF_ROOT_DIR.DIRECTORY_SEPARATOR.'/web/'.$asset->getFolderPath() . ':' . $asset->getFilename() . '…';

    sfAssetsLibraryTools::createThumbnails($asset->getFolderPath(), $asset->getFilename());

    echo "done!n";




  • cool! 🙂 thanks!