function _fivestar_color_mask in Fivestar 6.2
Same name and namespace in other branches
- 5 fivestar_color.inc \_fivestar_color_mask()
- 6 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 includes/
fivestar.color.inc - Apply a gradient to a portion of a black and white mask image.
- _fivestar_color_render in includes/
fivestar.color.inc - Render images that match a given palette.
File
- includes/
fivestar.color.inc, line 349 - 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);
}
}
}
}