This patch gently introduces Views-style exporting of imagecache presets. Exported presets can be provided in code by modules through hook_imagecache_presets(). Presets in code are collected when the imagecache preset cache is built. The patch distinguishes between presets in the database and presets in code by assigning a module-delta string identifier to presets from code.


  • Implement imagecache preset importing
  • Implement imagecache preset user-overrides (like Views)


moshe weitzman’s picture

Lovely. Thanks.

dopry’s picture

Version: 5.x-2.0-rc2 » 6.x-2.x-dev

I love the concept, but won't be adding new features to 2.0.

dopry’s picture

Status: Needs review » Needs work

I've finally had a chance to review this patch. It's really nice. The only fault I find is the way module defined presets are identified... I'd prefer they had a system flag in the presets table. Would you be up to making the alteration?

yhahn’s picture

Assigned: Unassigned » yhahn

Not a problem dopry.

Incidentally, I may be poking around and looking for a way to generalize the Milesian import/export/override/disable paradigm -- a "structures" module or API that provides a simple way for module developers to quickly implement the Views-style framework would be very handy (and reduce a lot of code duplication across modules).

drewish’s picture

yhahn, Any chance of getting you re-roll this against HEAD? I'd love to get it in.

laken’s picture

+1 for this! Anyone have a status?

greg.harvey’s picture

Likewise! Just wondering how to handle the installation of some imagecache presets in the hook_install() of my module - this would rock my world! =)

yhahn’s picture

Just a quick update -- this hasn't fallen off my radar entirely : )

I'll be returning to this, but probably with an even more views-ish approach for better caching/performance and simpler code.

yhahn’s picture

Here is the latest iteration of this patch -- it makes a few changes from the D5 version:

  • Default presets no longer use a namespace convention for their preset names. Instead, the preset is assigned a ['storage'] key at the time of preset caching (see imagecache_presets())
  • Preset overriding is now supported

Patched against checkout of CVS imagecache on Jan 30, 2009.

yhahn’s picture

Status: Needs work » Needs review
13.73 KB

One more iteration -- makes adjustments to the actions form theme function to respect default presets.

greg.harvey’s picture

Alrighty, this is late in the day, so you might want me to raise a separate feature request, but it falls in with the above. Are you planning to provide a hook so other modules can embed presets in their code, a la Views with hook_views_default_views (or whatever it's called).

That would be awesome! For me, as a module developer, that would be a real killer feature ... and with the export and import code written you're 80% there. =)

yhahn’s picture

Hey greg,

This is actually already implemented in the code above:

+    // Collect default presets and allow modules to modify them before they
+    // are cached.
+    $default_presets = module_invoke_all('imagecache_default_presets');
+    drupal_alter('imagecache_default_presets', $default_presets);

This allows you to use hook_imagecache_default_presets() where your module can provide an array of exported imagecache presets and hook_imagecache_default_presets_alter() if for some reason you are springboarding off of another module's presets and want to modify them.

greg.harvey’s picture

Awesome! Sorry for not checking properly before posting. I'll see if I get chance to review your patch on Wednesday. Very exciting! Great additions! =)

drewish’s picture

wow, this looks great. i'm going to roll a release right now to get some bug fixes out but i definitely want this in the next one.

drewish’s picture

yhahn, I just added a imagecache.api.php to HEAD as a place to document the module's hooks. We should document the new hook_imagecache_default_presets() there.

q0rban’s picture

Wow, this is awesome, no more adding presets manually on hook_install! Haven't tested it, but if it does everything described above it certainly gets my vote...

yhahn’s picture

Patch updated to apply cleanly to imagecache d6 HEAD. I've also added hook_imagecache_default_presets() to imagecache.api.php.

drewish’s picture

Status: Needs review » Fixed

great, thanks for sticking with this. committed to HEAD. going to roll a new release in a few minutes.

yhahn’s picture

Thanks drewish!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Alan D.’s picture

This is a very cool feature. It has become the default way we define presets for clients as they can't screw things up! Nice work.

Any chances for a 5 backport sometime? I know Drupal 5 is almost dead, but we have a few clients where upgrading to Drupal 6 is currently not an option.


NancyDru’s picture

Status: Closed (fixed) » Active

Okay, so I'm stupid. I exported the code and tried in both my main module file and .install file. How does it get invoked to define the preset?

The docs at don't seem to be much help here.

NancyDru’s picture

Status: Active » Needs work

I finally figured it out. The export does not include a return $presets; and it should. I also had to move the hook_install into the main module to make it work (probably a path problem).

And now that I look at it, is it possible to change the export so that it can be more properly copied into a module?
A) it is not indented
B) there are array openings where the word "array" is on the next line (e.g. on "data")

  $presets['content-teaser'] = array (
    'presetname' => 'content-teaser',
    'actions' => array (
        0 => array (
          'weight' => '-10',
          'module' => 'imagecache',
          'action' => 'imagecache_scale',
          'data' => array (
            'width' => '200',
            'height' => '200',
            'upscale' => 0,
        1 => array (
          'weight' => '-9',
          'module' => 'imagecache_textactions',
          'action' => 'textactions_text2canvas',
          'data' => array (
            'size' => '9',
            'angle' => '0',
            'alpha' => '100',
            'xpos' => 'left+1',
            'ypos' => 'bottom-10',
            'RGB' => array (
              'HEX' => 'ffffff',
            'fontfile' => 'liberation-fonts-1.04/LiberationSans-Regular.ttf',
            'text' => '  return $file_data->description;',
            'evaluate_text' => 1,
lpalgarvio’s picture

nice idea. +1.
subscribing, keep up the work

fizk’s picture

Issue tags: +ImageCache 3

Marking as ImageCache 3.x Todo.