protected static function GDToolkitReflect::imagecopymergeAlpha in ImageCache Reflect 8
A fix to get a function like imagecopymerge with alpha blending.
Main script by aiden dot mail at freemail dot hu. Transformed to imagecopymerge_alpha() by rodrigo dot polo at gmail dot com.
Parameters
resource $dst_im : Destination image link resource.
resource $src_im: Source image link resource.
int $dst_x: x-coordinate of destination point.
int $dst_y: y-coordinate of destination point.
int $src_x: x-coordinate of source point.
int $src_y: y-coordinate of source point.
int $src_w: Source width.
int $src_h: Source height.
int $pct: Opacity in percent * 100.
int $minalpha: Minimum alpha value in the image resource.
Return value
bool Returns TRUE on success or FALSE on failure.
See also
http://uk3.php.net/manual/en/function.imagecopymerge.php#88456
1 call to GDToolkitReflect::imagecopymergeAlpha()
- GDToolkitReflect::reflect in lib/
Drupal/ imagecache_reflect/ Plugin/ ImageToolkit/ GDToolkitReflect.php - Creates an image with a reflection-like effect from a provided image.
File
- lib/
Drupal/ imagecache_reflect/ Plugin/ ImageToolkit/ GDToolkitReflect.php, line 169 - Contains \Drupal\imagecache_reflect\Plugin\ImageToolkit\GDToolkitReflect.
Class
- GDToolkitReflect
- Creates a reflect operation for the GD library.
Namespace
Drupal\imagecache_reflect\Plugin\ImageToolkitCode
protected static function imagecopymergeAlpha(&$dst_im, &$src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct, $minalpha = NULL) {
if (!isset($pct)) {
return FALSE;
}
$pct /= 100;
// Get image width and height.
$w = imagesx($src_im);
$h = imagesy($src_im);
// Turn alpha blending off.
imagealphablending($src_im, FALSE);
if (is_null($minalpha)) {
// 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;
}
}
}
}
// Loop through image pixels and modify alpha for each.
for ($x = $src_x; $x < $src_x + $src_w; $x++) {
for ($y = $src_y; $y < $src_y + $src_h; $y++) {
// Get current alpha value (represents the transparency).
$colorxy = imagecolorat($src_im, $x, $y);
$alpha = $colorxy >> 24 & 0xff;
// Calculate new alpha.
if ($minalpha !== 127) {
$alpha = 127 + 127 * $pct * ($alpha - 127) / (127 - $minalpha);
}
else {
$alpha += 127 * $pct;
}
// Get the color index with new alpha.
$alphacolorxy = imagecolorallocatealpha($src_im, $colorxy >> 16 & 0xff, $colorxy >> 8 & 0xff, $colorxy & 0xff, $alpha);
// Set pixel with the new color + opacity.
if (!imagesetpixel($src_im, $x, $y, $alphacolorxy)) {
return FALSE;
}
}
}
// The image copy.
imagecopy($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
}