You are here

function imagecache_proportions_calculate_proportions in Imagecache Proportions 7

Same name and namespace in other branches
  1. 6 imagecache_proportions.module \imagecache_proportions_calculate_proportions()

Helper function to guess if the image is wider, higher or "squarer" taking a look to the looseness.

2 calls to imagecache_proportions_calculate_proportions()
ImagecacheProportionsTestCase::testCalculateProportions in ./imagecache_proportions.test
Tests if the image style is well calculated from image size.
imagecache_proportions_field_formatter_view in ./imagecache_proportions.module
Implements hook_field_formatter_view().

File

./imagecache_proportions.module, line 246
Field formatter for image fields that allows the user to select between 3 different image styles depending on the proportions of the original image uploaded. One style would be squared for more or less squared images, another for wider images and the…

Code

function imagecache_proportions_calculate_proportions($width, $height, $looseness) {
  if ($width == $height || abs($width - $height) <= $looseness) {
    return 'squared_preset';
  }
  if ($width > $height) {
    return 'horizontal_preset';
  }
  if ($height > $width) {
    return 'vertical_preset';
  }
}