protected function _mask($maskimage) { extract(parent::_mask($maskimage)); $wmimage = new \Imagick(); $wmimage->readImage($maskimage); $wmimage->setImageMatte(false); $this->imagick->compositeImage($wmimage, \Imagick::COMPOSITE_COPYOPACITY, 0, 0); }
protected function _mask($maskimage) { extract(parent::_mask($maskimage)); $mimage = '"' . $maskimage . '"'; $image = '"' . $this->image_temp . '"'; $command = $image . ' ' . $mimage . ' +matte -compose copy-opacity -composite ' . $image; $this->exec('convert', $command); }
protected function _mask($maskimage) { extract(parent::_mask($maskimage)); // Get size and width of image $sizes = $this->sizes(); $masksizes = $this->sizes($maskimage); // Create new blank image $image = $this->create_transparent_image($sizes->width, $sizes->height); if (is_resource($maskimage)) { $maskim = $maskimage; } else { $maskim = $this->load($maskimage, true); } $masksizes->width > $sizes->width and $masksizes->width = $sizes->width; $masksizes->height > $sizes->width and $masksizes->height = $sizes->height; // Loop through all the pixels for ($x = 0; $x < $masksizes->width; $x++) { for ($y = 0; $y < $masksizes->height; $y++) { $maskcolor = imagecolorat($maskim, $x, $y); $maskcolor = imagecolorsforindex($maskim, $maskcolor); $maskalpha = 127 - floor(($maskcolor['red'] + $maskcolor['green'] + $maskcolor['blue']) / 6); if ($maskalpha == 127) { continue; } if ($maskalpha == 0) { $ourcolor = array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 0); } else { $ourcolor = imagecolorat($this->image_data, $x, $y); $ourcolor = imagecolorsforindex($this->image_data, $ourcolor); } $ouralpha = 127 - $ourcolor['alpha']; if ($ouralpha == 0) { continue; } $newalpha = floor($ouralpha - $maskalpha / 127 * $ouralpha); $newcolor = imagecolorallocatealpha($image, $ourcolor['red'], $ourcolor['green'], $ourcolor['blue'], 127 - $newalpha); imagesetpixel($image, $x, $y, $newcolor); } } $this->image_data = $image; }