How can you make imagecache play nicely with a site that supports multiple themes?

An imagecache preset typically includes a 'scale and crop' action to resize an image so that it fits nicely in the site's theme. Often, the themes custom node templates will reference imagecache pesets by name.

So, if you wanted your site to support 2 quite different themes, where the images need to be displayed at different sizes depending on the themes, what would be the best / most appropriate way of doing this?

As far as I can see, the options are:

1) Define 2 copies of each style (where the name of the style is prefixed with the name of the theme so it's easy to identify which preset goes with which theme). So you might have theme1_thumbnail and theme2_thumbnail. Then, the theme can use the appropriate one in it's templates (theme('imagescache', 'theme1_thumbnail' ...). Whilst this is easy to do it just feels wrong to load up the database with theme specific Imagecache presets.

2) Create the imagecache presets on the fly in the theme layer somewhere - but I'm not sure if this is possible or how you would do it.

3) Override the imagecache presets in you're template.php file for each theme - this seems like it would be a good approach, but again I have no idea if it's possible of how you would do it. Does Imagecache provide any kind of preprocess function to allow for this?

Any ideas or other suggestions?!

Comments

mstrelan’s picture

Category: support » feature

Subscribe. I think there should be a way to pass in arguments to a preset. Perhaps theme_imagecache should have a keyed array that you can pass in values. The keys would be generated on the action page. For example scale_and_crop_width, scale_and_crop_height. Obviously if you had more than 1 scale and crop action it could create scale_and_crop1_width or something like that. There's probably a better way

mrfelton’s picture

I wonder if http://drupal.org/project/designkit holds the answer.

hefox’s picture

I achieved something similar via overriding theme_imagecache in a base theme and looked if the preset had a version pre-pended with the current active theme key and using that instead original preset; so far it's working fine.

The imagecache presets were created via the imagecache default preset hook (forgot exact hook name) based on theme variables that indicated what size the crops had to be, so set up was not a worry.

fizk’s picture

Status: Active » Closed (fixed)

Please reopen if this is still an issue with ImageCache 6.x-2.0-rc1.