15 $mask_source = $this->
argument(0)->value();
16 $mask_w_alpha = $this->
argument(1)->type(
'bool')->value(
false);
18 $image_size = $image->getSize();
21 $canvas = $image->getDriver()->newImage($image_size->width, $image_size->height, array(0,0,0,0));
24 $mask = $image->getDriver()->init($mask_source);
25 $mask_size = $mask->getSize();
28 if ($mask_size != $image_size) {
29 $mask->resize($image_size->width, $image_size->height);
32 imagealphablending($canvas->getCore(),
false);
34 if ( ! $mask_w_alpha) {
36 imagefilter($mask->getCore(), IMG_FILTER_GRAYSCALE);
40 for ($x=0; $x < $image_size->width; $x++) {
41 for ($y=0; $y < $image_size->height; $y++) {
43 $color = $image->pickColor($x, $y,
'array');
44 $alpha = $mask->pickColor($x, $y,
'array');
57 $alpha = floatval(round($alpha[0] / 255, 2));
63 if ($color[3] < $alpha) {
71 $canvas->pixel($color, $x, $y);
77 $image->setCore($canvas->getCore());