How to properly override Drupal imagecache presets

Posted by volocuga on Stack Overflow See other posts from Stack Overflow or by volocuga
Published on 2011-01-09T12:52:29Z Indexed on 2011/01/09 12:53 UTC
Read the original article Hit count: 183

Filed under:
|

Say I need to override defaul presets, provided by Ubercart module. This is what I wrote:

function config_imagecache() {
$presets = array(
    array(
      'presetname' => 'product',
      'actions' => array(
        array(
          'action' => 'imagecache_crop',
          'data' => array('width' => 300, 'height' => ''),
          'weight' => 0,
          'module' => 'imagecache',      
        ),
array(
          'action' => 'canvasactions_canvas2file',
          'data' => array('xpos' => 'center', 'ypos' => 'center', 'path' => 'actions/pad_300_300.gif', 'dimensions' => 'background',),
          'weight' => 1,
          'module' => 'imagecache_canvasactions',      
        ),
      ),
    ),
    array(
      'presetname' => 'uc_thumbnail',
      'actions' => array(
        array(
          'action' => 'imagecache_scale',
          'data' => array('width' => 55, 'height' => 55, 'upscale' => 0),
          'weight' => 0,
          'module' => 'imagecache',      
        ),
array(
          'action' => 'canvasactions_canvas2file',
          'data' => array('xpos' => 'center','ypos' => 'center', 'path' => 'actions/pad_60_60.gif','dimensions' => 'background'),
          'weight' => 1,
          'module' => 'imagecache_canvasactions',      
        ),
      ),
    ),
    array(
      'presetname' => 'product_full',
      'actions' => array(
        array(
          'action' => 'imagecache_scale',
          'data' => array('width' => 600, 'height' => 600, 'upscale' => 0),
          'weight' => 0,
          'module' => 'imagecache',      
        ),
      ),
    ),
    array(
      'presetname' => 'product_list',
      'actions' => array(
        array(
          'action' => 'imagecache_scale',
          'data' => array('width' => 100, 'height' => 100, 'upscale' => 0),
          'weight' => 0,
          'module' => 'imagecache',      
        ),
array(
          'action' => 'canvasactions_canvas2file',
          'data' => array('xpos' => 'center', 'ypos' => 'center', 'path' => 'actions/pad_100_100.jpg','dimensions' => 'background',),
          'weight' => 1,
          'module' => 'imagecache_canvasactions',      
        ),
      ),
    ),
    array(
      'presetname' => 'uc_category',
      'actions' => array(
        array(
          'action' => 'imagecache_scale',
          'data' => array('width' => 100, 'height' => 100, 'upscale' => 0),
          'weight' => 0,
          'module' => 'imagecache',      
        ),
array(
          'action' => 'canvasactions_canvas2file',
          'data' => array('xpos' => 'center', 'ypos' => 'center', 'path' => 'actions/pad_100_100.gif', 'dimensions' => 'background',),
          'weight' => 1,
          'module' => 'imagecache_canvasactions',      
        ),
      ),
    ),
array(
      'presetname' => 'cart',
      'actions' => array(
        array(
          'action' => 'imagecache_scale',
          'data' => array('width' => 50, 'height' => 50, 'upscale' => 0),
          'weight' => 0,
          'module' => 'imagecache',      
        ),
array(
          'action' => 'canvasactions_canvas2file',
          'data' => array('xpos' => 'center', 'ypos' => 'center', 'path' => 'actions/pad_60_60.gif', 'dimensions' => 'background',),
          'weight' => 1,
          'module' => 'imagecache_canvasactions',      
        ),
      ),
    ),
  );

    foreach ($presets as $preset) {
    drupal_write_record('imagecache_preset', $preset);
    foreach ($preset['actions'] as $action) {
      $action['presetid'] = $preset['presetid'];
      drupal_write_record('imagecache_action', $action);
    }
  }

  imagecache_presets(true);
  cache_clear_all('imagecache:presets', 'cache');
}

I can see in imagecache UI the settings was applied, but really images disappeared at all. Nothing works now.

Where is the mistake?

© Stack Overflow or respective owner

Related posts about drupal

Related posts about drupal-module