You are here

function taxonomy_image_resize in Taxonomy Image 6

Same name and namespace in other branches
  1. 5 taxonomy_image.module \taxonomy_image_resize()

Function to resize the image.

1 call to taxonomy_image_resize()
taxonomy_image_display in ./taxonomy_image.module
Function to display the image associated with the given term id. An html <img> tag will be returned if an image is found. The link format can be modified with the tags parameter.
3 string references to 'taxonomy_image_resize'
taxonomy_image_admin_form in ./taxonomy_image.admin.inc
taxonomy_image_display in ./taxonomy_image.module
Function to display the image associated with the given term id. An html <img> tag will be returned if an image is found. The link format can be modified with the tags parameter.
taxonomy_image_uninstall in ./taxonomy_image.install
Implementation of hook_uninstall().

File

./taxonomy_image.module, line 117
taxonomy_image.module Simple module for providing an association between taxonomy terms and images. Written by Jeremy Andrews <jeremy@kerneltrap.org>, May 2004.

Code

function taxonomy_image_resize($image, $resize, $width = NULL, $height = NULL) {
  switch ($resize) {
    case 3:

      // Exact.
      if ($width) {
        $image->width = $width;
      }
      if ($height) {
        $image->height = $height;
      }
      break;
    case 2:

      // Not less than.
      if ($width && $width > $image->width) {
        $width_scale = $image->width / $width;
      }
      if ($height && $height > $image->height) {
        $height_scale = $image->height / $height;
      }
      if ($height_scale || $width_scale) {
        if ($width_scale && $height_scale) {
          $scale = min($width_scale, $height_scale);
        }
        else {
          $scale = $width_scale ? $width_scale : $height_scale;
        }
        $image->height = round($image->height / $scale);
        $image->width = round($image->width / $scale);
      }
      break;
    case 1:

      // Not greater than.
      if ($width && $width < $image->width) {
        $width_scale = $image->width / $width;
      }
      if ($height && $height < $image->height) {
        $height_scale = $image->height / $height;
      }
      if ($height_scale || $width_scale) {
        $scale = max($width_scale, $height_scale);
        $image->height = round($image->height / $scale);
        $image->width = round($image->width / $scale);
      }
      break;
    case 0:

      // Disabled, just leave them as is.
      break;
  }
}