You are here

function _imagecache_reflect_alpha_get_min in ImageCache Reflect 7

Compute the minimum alpha value of the pixels of a given image resource.

Warning, this function is very expensive.

1 call to _imagecache_reflect_alpha_get_min()
imagecache_reflect_image in ./imagecache_reflect.module
Implements hook_image().

File

./imagecache_reflect.module, line 305
Adds a reflection action for images.

Code

function _imagecache_reflect_alpha_get_min($src_im) {
  $w = imagesx($src_im);
  $h = imagesy($src_im);

  // Turn alpha blending off.
  imagealphablending($src_im, FALSE);

  // Find the most opaque pixel in the image (smallest alpha value).
  $minalpha = 127;
  for ($x = 0; $x < $w; $x++) {
    for ($y = 0; $y < $h; $y++) {
      $alpha = imagecolorat($src_im, $x, $y) >> 24 & 0xff;
      if ($alpha < $minalpha) {
        $minalpha = $alpha;
      }
    }
  }
  return $minalpha;
}