Skip to content

Watermark transparency #2

@webbird

Description

@webbird

We discussed this on your HP some time ago. I maybe have a solution. Try this code:


public function writeWatermark($opacity=50, $marginH=0, $marginV=0, $positionWatermarkLeftRight="c", $positionWatermarkTopBottom="c"){

    //Watermark
    list($image_create_func, $image_save_func) = $this->Watermark->getFunctionNames();
    $watermark = $image_create_func($this->Watermark->getImage());

    //get base image
    list($image_create_func, $image_save_func) = $this->getFunctionNames();
    $baseImage = $image_create_func($this->image);

    imagealphablending($baseImage, true);
    imagesavealpha($baseImage, true);

    imagealphablending($watermark, true);
    imagesavealpha($watermark, true);

    // resize the watermark to fit original image size
    //imagecopy( $baseImage, $watermark, 0, 0, 0, 0, imagesx($watermark), imagesy($watermark));
    imagecopyresampled( $baseImage, $watermark, 0, 0, 0, 0, imagesx($baseImage), imagesy($baseImage), imagesx($watermark), imagesy($watermark));

    //Set image
    if(!$image_save_func($baseImage, $this->tmpfile)){
        throw new Exception("Cannot save file ".$this->tmpfile);
    }//if

    //Set new main image
    $this->setNewMainImage($this->tmpfile);

    //Free memory!
    imagedestroy($baseImage);
    unset($Watermark);

}//function

I tried this with PNG and JPG as base image and PNG as watermark image. It also resizes the watermark to fit the base image size. I've still got to do some testing, but maybe you'd like to check this meanwhile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions