If your presets are loading from code (default presets), you get whatever you configured ad the default dummy image dimensions instead.

CommentFileSizeAuthor
#1 presets_in_code.patch722 bytesjonhattan

Comments

jonhattan’s picture

Status: Active » Needs review
StatusFileSize
new722 bytes

Here's a patch

manuel garcia’s picture

Status: Needs review » Needs work

Patch applies fine, and apparently gets the width correctly, but the height is not correctly detected, it gets the same height as the width.

manuel garcia’s picture

Just a pointer that might be helpful, in my module galleryformatter I have a similar function, perhaps you'll find it useful:

/**
  * Helper function to get dimensions of an image
  *
  * @return array
  * An array key => value pairs
  * width => value and height => value, not including px
  */
function galleryformatter_getimage_dimensions($presetname, $image_path) {
  // generate the imagecache preset image path
  $transformed_path = imagecache_create_path($presetname, $image_path);
  // grab the preset itself
  $preset = imagecache_preset_by_name($presetname);

  // get the default presets names provided by galleryformatter
  foreach (galleryformatter_imagecache_default_presets() as $key => $value) {
    $default_presets[] = $value['presetname'];
  }
  // if using the default preset no need to get image info
  $default_preset = in_array($preset['presetname'], $default_presets);
  if (($preset['storage'] == 1) && $default_preset){
    $ret['height'] = $preset['actions'][0]['data']['height'];
    $ret['width'] = $preset['actions'][0]['data']['width'];
  }
  // otherwise check if file exists, or create it so we can get the image dimensions
  elseif (file_exists($transformed_path) || imagecache_build_derivative($preset['actions'], $image_path, $transformed_path)) {
    // grab the image information
    $image = image_get_info($transformed_path);
    $ret['height'] = $image['height'];
    $ret['width'] = $image['width'];
  }
  return $ret;
}
manuel garcia’s picture

A sample default preset wehre the dummy image gets the same height as its width with the patch:

$presets['largethumbnail'] = array (
    'presetname' => 'Large thumbnail',
    'actions' =>
    array (
      0 =>
      array (
        'weight' => '0',
        'module' => 'imagecache',
        'action' => 'imagecache_scale_and_crop',
        'data' =>
        array (
          'width' => '192px',
          'height' => '115px',
        ),
      ),
    ),
  );
jonhattan’s picture

my presets looks like:

$presets['destacado-lateral'] = array (
  'presetname' => 'destacado-lateral',
  'actions' =>
  array (
    0 =>
    array (
      'weight' => '0',
      'module' => 'imagecache',
      'action' => 'imagecache_scale_and_crop',
      'data' =>
      array (
        'width' => '371',
        'height' => '209',
      ),
    ),
  ),
);
manuel garcia’s picture

we've just found out that if the default preset DOESN'T have 'px' in its width/height, the patch works properly.

manuel garcia’s picture

Status: Needs work » Reviewed & tested by the community

I think the patch is good to go. Having px in the presets is no use and a bad idea, but that's something that should be tackled in imageacache itself i suppose.

jonhattan’s picture

For the record imagecache doesn't even have a match for 'px' in its code. I wonder how this is working for you.

jonhattan@larry:/tmp$ drush dl imagecache-6.x
Project imagecache (6.x-2.0-beta10) downloaded to /tmp/imagecache.                                                                                [success]
Project imagecache contains 2 modules: imagecache, imagecache_ui.
jonhattan@larry:/tmp$ rgrep px imagecache/*
naxoc’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Committed :) Thanks!

And you are right about the -px suffix, Jonhattan. I think it used to be around but got deprecated some time ago.