Upgrade your imagecache presets to D7 image styles via features

Created on 20 October 2011, about 13 years ago
Updated 27 May 2024, 7 months ago

Here's how I migrated my D6 imagecache presets to D7 image styles:

1. I exported all of my imagecache presets on the D6 site via features into a features module.

2. I changed the features module's .info file to be a 7.x module.

3. I added the following to its .module file:


function MY_FEATURE_NAME_image_styles_alter(&$styles) {
  foreach (module_implements('imagecache_default_presets') as $module) {
    $module_styles = module_invoke($module, 'imagecache_default_presets');
    foreach ($module_styles as $style_name => $style) {
      $style['name'] = $style_name;
      $style['module'] = $module;
      $style['storage'] = IMAGE_STORAGE_DEFAULT;
      foreach ($style['actions'] as $key => $effect) {
        $effect['action'] = str_replace('cache', '', $effect['action']);
        $definition = image_effect_definition_load($effect['action']);
        $effect = array_merge($definition, $effect);
        $style['effects'][$key] = $effect;
      }
      $styles[$style_name] = $style;
    }
  }
}

4. I enabled the module on the D7 site. Voila my image styles are now all loaded in D7.

5. I recreated the feature module on the D7 site and added all the new image styles to it (as opposed to what were imagecache presets).

6. I removed the function I added in 3.

πŸ“Œ Task
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Jody Lynn

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡ͺGermany asb

    The code from #20 reports:

    Styles: 10, Effects new: 19, Effects exists: 0

    The D6 Imagecache presets now do show up at ./admin/config/media/image-styles.

    Also tried Jen's module from #11, same result.

    Made a 'drush cc all', but for whatever reason the converted presets seem not to be used anywhere. Is anyone else getting this too?

    Anyway, these litte migration helpers are (potentially) incredibly useful, so many thanks for it!

Production build 0.71.5 2024