You are here

function _media_crop_scale in Media crop 7

Scaling helper.

Parameters

double $image_width: Original image width.

double $image_height: Original image height.

double $val: Value to scale.

bool $invert: TRUE if you want to convert from original size to UI units. FALSE if you want to convert from UI units to original size.

Return value

string Scaled value.

2 calls to _media_crop_scale()
_media_crop_apply_crop in ./media_crop.module
Helper function to apply crop to an image.
_media_crop_extract_rotation_and_crop in ./media_crop.module
Extracts the rotation and crop information from an image effect list.

File

./media_crop.module, line 877
Media crop primary module file.

Code

function _media_crop_scale($image_width, $image_height, $val, $invert = FALSE) {
  static $precision = 4096;
  $cache =& drupal_static(__FUNCTION__, array());
  $cache_index = "{$image_width}x{$image_height}";
  if (!isset($cache[$cache_index])) {
    $cache[$cache_index] = function_exists('bcdiv') ? bcdiv(350, max($image_width, $image_height), $precision) : 350 / max($image_width, $image_height);
  }
  return $invert ? function_exists('bcmul') ? bcmul($val, $cache[$cache_index], $precision) : $cache[$cache_index] * $val : (function_exists('bcdiv') ? bcdiv($val, $cache[$cache_index], $precision) : $cache[$cache_index] / $val);
}