Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comments
An easier way to do this
There is now an easier way to do it with imagecache 6.x-2.0-beta10 (and higher, not sure about beta9 or lower). Simply use the following code in your custom module. No need for install hooks. Once this code is in your module, its shown on imagecache page. All you do is export your preset using the Export link and paste that code in the module.
______________________________________________________________________________________________________
Thanks a lot
The module is really well constructed. I'm using it for a project of mine, and I'm amazed at the flexibility of the code.
This last post is excellent.
I agree
Really amazing tool! thumbs up
Thx for this code snippet. No long search just use.
And yet another way of doing
And yet another way of doing this, starting with an exported preset:
Check the code. I didn't test it.
Tested, added a little fix, working great.
I have tested the code and fixed it a bit.