Linked Questions

Popular Questions

Add transparent watermark into image

Asked by At

I need to add transparent watermark (transparency in final image - 80%). I created this function to handle it:

function ImageAddWatermark($im, $stamp, $onLeft, $onTop, $margin){       
        // $stamp = imagecreatformpng(...) -> GD resource?
        // not important part - it calculates position of watermark 
            $orgX = $margin;
        } else {
            $orgX = imagesx($im)-$margin-imagesx($stamp);

            $orgY = $margin;
        }else {
            $orgY = imagesy($im)-$margin-imagesy($stamp);

        imagecopymerge($im, $stamp, $orgX, $orgY, 0, 0, imagesx($stamp), imagesy($stamp), 50);

        return $im;

Result of function: error

But imagecopymerge returns black background instead of transparent. I even heard some opinions, that imagecopymerge isn't exactly the right thing for creating transparent watermarks...

So the question is: "How can I add a transparent watermark (using alpha?) in jpeg photo?" How can I get rid of that black backgound? (In original PNG file is transparent)

Related Questions