Skip to content

Commit

Permalink
Added alpha blanding for transparent PNG watermarks
Browse files Browse the repository at this point in the history
  • Loading branch information
danrwalker committed May 2, 2019
1 parent 7e38ee0 commit 3b9d553
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions dist/twist/Core/Models/Image/Image.model.php
Expand Up @@ -47,7 +47,7 @@ public function __destruct(){
return (is_resource($this->resImage)) ? imagedestroy($this->resImage) : null;
}

protected function load($mxdImage){
protected function load($mxdImage,$blAlphaBlending = true){

if(preg_match('#^data:image/[^;]+;base64,(.*)$#',$mxdImage,$arrMatches)){

Expand Down Expand Up @@ -98,8 +98,10 @@ protected function load($mxdImage){
'mime' => $arrImageInfo['mime']
);

imagealphablending($this->resImage, false);
imagesavealpha($this->resImage, true);
if($blAlphaBlending){
imagealphablending($this->resImage, $blAlphaBlending);
imagesavealpha($this->resImage, true);
}
}

protected function create($intWidth,$intHeight,$strFillColour = null){
Expand Down Expand Up @@ -1002,11 +1004,12 @@ public function filterSmooth($intLevel = 0){
* @param null|integer $intHeight Output height of the watermark image
* @param null|integer $intAlphaTransparency Set the alpha transparency of the watermark
* @return Image
* @throws \Exception
*/
public function watermark($strFilename,$intMarginRight = 30,$intMarginBottom = 30,$intWidth = null,$intHeight = null,$intAlphaTransparency = 0){

$resWatermark = new self();
$resWatermark->load($strFilename);
$resWatermark->load($strFilename,true);

//Resize the image if required
if(!is_null($intWidth) && !is_null($intHeight)){
Expand Down

0 comments on commit 3b9d553

Please sign in to comment.