Create imagecache preset programmatically in D6

Last updated on
30 April 2025

You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules

If you need to create your own imagecache presets from code have a look at following example:

// Preset
  $imagecachepreset = imagecache_preset_save(array('presetname' => 'MYPRESETNAME'));
  // Action
  $imagecacheaction = new stdClass ();
  $imagecacheaction->presetid = $imagecachepreset['presetid'];
  $imagecacheaction->module = 'imagecache';
  $imagecacheaction->action = 'imagecache_scale_and_crop';
  $imagecacheaction->data = array('width' => '200', 'height' => '200' );
  drupal_write_record('imagecache_action', $imagecacheaction);

Thanks to Eikaa & mavimo for this

If you call this in your _install hook the preset gets installed when your module is enabled.
Now for uninstalling this imagecache preset in this case you can do the following:

imagecache_preset_delete(imagecache_preset_by_name('MYPRESETNAME'));
Thanks to tylerwaits for this

Help improve this page

Page status: Not set

You can: