You are here

function _fivestar_color_mask in Fivestar 6

Same name and namespace in other branches
  1. 5 fivestar_color.inc \_fivestar_color_mask()
  2. 6.2 includes/fivestar.color.inc \_fivestar_color_mask()

Apply a color to a portion of a black and white mask image.

Parameters

$mask: A GD image reference containing the mask image.

$color: A hex color value (i.e. ffdd00) to apply to the mask.

2 calls to _fivestar_color_mask()
_fivestar_color_mask_linear_gradient in ./fivestar_color.inc
Apply a gradient to a portion of a black and white mask image.
_fivestar_color_render in ./fivestar_color.inc
Render images that match a given palette.

File

./fivestar_color.inc, line 306
File containing functions relating to the color widget.

Code

function _fivestar_color_mask(&$mask, $color, $matte_color, $x_offset, $y_offset, $width, $height) {
  $rgb = _fivestar_color_unpack($color);
  for ($x = $x_offset; $x < $x_offset + $width; $x++) {
    for ($y = $y_offset; $y < $y_offset + $height; $y++) {
      $current_pixel = imagecolorsforindex($mask, imagecolorat($mask, $x, $y));
      $new_color = imagecolorallocatealpha($mask, $rgb[0], $rgb[1], $rgb[2], $current_pixel['alpha']);

      // Matte coloring:
      if ($matte_color != 'transparent' && $current_pixel['alpha'] != 127) {
        $matte_rgb = _fivestar_color_unpack($matte_color);
        $matte = imagecolorallocate($mask, $matte_rgb[0], $matte_rgb[1], $matte_rgb[2]);
        imagealphablending($mask, FALSE);
        imagesetpixel($mask, $x, $y, $matte);
        imagealphablending($mask, TRUE);
        imagesetpixel($mask, $x, $y, $new_color);
      }
      else {
        imagealphablending($mask, FALSE);
        imagesetpixel($mask, $x, $y, $new_color);
        imagealphablending($mask, TRUE);
      }
    }
  }
}