PHP 8.5.0 Alpha 1 available for testing

Voting

: min(one, nine)?
(Example: nine)

The Note You're Voting On

ragnar_40k at hotmail dot com
19 years ago
Here a function to make holes into images:

// Set the alpha channel for a part of an image (it ignores the canvas alpha atm).
// $img_canvas - 32-bit true color image w/ alpha channel
// $img_mask - 8-bit gray scale image (white parts will be masked transparent in the canvas).
// This relies on the current pixel format:
// (high byte) -> (alpha channel} {red} {green} {blue} <- (low byte)
function mask($img_canvas, $img_mask, $dst_x, $dst_y)
{
$old_blendmode = imagealphablending($img_canvas, FALSE);

$width = imagesx($img_mask);
$heigth = imagesy($img_mask);

$mask_x = 0;
$x = $dst_y;
while ($mask_x<$width)
{
$mask_y = 0;
$y = $dst_y;
while ($mask_y<$heigth)
{
imagesetpixel($img_canvas, $x, $y,
((imagecolorat($img_mask, $mask_x, $mask_y) >> 1) << 24) | (imagecolorat($img_canvas, $x, $y) & 0x00FFFFFF));

++$mask_y;
++$y;
}
++$mask_x;
++$x;
}

imagealphablending($img_canvas, $old_blendmode);
}

<< Back to user notes page

To Top