Skip to content

Commit

Permalink
fixed using watermark images using alphablending
Browse files Browse the repository at this point in the history
  • Loading branch information
WanWizard committed Apr 12, 2016
1 parent 3120979 commit c55321c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions classes/image/gd.php
Expand Up @@ -128,6 +128,7 @@ protected function _watermark($filename, $position, $padding = 5)
$x = $x < 0 ? 0 : $x;
$y = $y < 0 ? 0 : $y;
}

// Used as a workaround for lack of alpha support in imagecopymerge.
$this->debug("Coords for watermark are $x , $y");
$this->image_merge($this->image_data, $watermark, $x, $y, $this->config['watermark_alpha']);
Expand Down Expand Up @@ -546,12 +547,28 @@ protected function round_corner(&$image, $radius, $antialias, $top, $left)
*/
protected function image_merge(&$image, $watermark, $x, $y, $alpha)
{
// get the watermark dimensions
$wsizes = $this->sizes($watermark);

// creating a cut resource
$tmpimage = $this->create_transparent_image($wsizes->width, $wsizes->height);

// copying relevant section from background to the cut resource
imagecopy($tmpimage, $image, 0, 0, $x, $y, $wsizes->width, $wsizes->height);

// copying relevant section from watermark to the cut resource
imagecopy($tmpimage, $watermark, 0, 0, 0, 0, $wsizes->width, $wsizes->height);
imagealphablending($image, false);
imagecopymerge($image, $tmpimage, $x, $y, 0, 0, $wsizes->width, $wsizes->height, $alpha);
imagealphablending($image, true);

// insert cut resource to destination image
if (imagecolortransparent($watermark) == -1)
{
imagealphablending($image, false);
imagecopymerge($image, $tmpimage, $x, $y, 0, 0, $wsizes->width, $wsizes->height, $alpha);
imagealphablending($image, true);
}
else
{
imagecopy($image, $tmpimage, $x, $y, 0, 0, $wsizes->width, $wsizes->height);
}
}
}

0 comments on commit c55321c

Please sign in to comment.