Just did a cachegrind and getimagesize() took 1,093ms for 8 calls. I'm using memcache so if we were to store this info in a cache_imagecache bin I'm guessing that would be quicker. image_get_info() is where this PHP function is called, so I'm proposing having cache_get/set be in theme_imagecache().

Thoughts? Create my own module and overwrite this theme function? Preprocess function?

files dir is a S3 mount thus its a little bit slower.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeytown2’s picture

hook_theme_registry_alter seems to be the answer I was looking for.

function imageinfo_cache_theme_registry_alter(&$theme_registry) {
  if (isset($theme_registry['imagecache'])) {
    variable_set('imageinfo_cache_theme_imagecache_function', $theme_registry['imagecache']['function']);
    $theme_registry['imagecache']['function'] = 'imageinfo_cache_theme_imagecache';
  }
}

function imageinfo_cache_theme_imagecache() {
  $args = func_get_args();

  // Use cached data if available
  $path = imagecache_create_path($args[0], $args[1]);
  $cid = md5($path);
  $image = cache_get($cid, 'cache_imageinfo');
  if ($image) {
    $image = $image->data;
  }
  else {
    $image = image_get_info($path);
    // Cache for 24 hours
    cache_set($cid, $image, 'cache_imageinfo', time() + (60 * 60 * 24));
  }
  if ($image) {
    $attributes['width'] = $image['width'];
    $attributes['height'] = $image['height'];
    $args[4] = array_merge($args[4], $attributes);
    $args[5] = FALSE;
  }

  // Run original function
  $function = variable_get('imageinfo_cache_theme_imagecache_function', 'theme_imagecache');
  call_user_func_array($function, $args);
}

This something you want or should I put it in a new module called imageinfo_cache?

mikeytown2’s picture

Status: Active » Closed (works as designed)

if files are local image_get_info is faster, so this should live outside this module.

mikeytown2’s picture

FileSize
872 bytes

module if anyone else has this issue

mikeytown2’s picture

FileSize
875 bytes

fixed a big error with the last module.

mcdruid’s picture