Jump to content

transparent water mark for uploaded images


sungpeng

Recommended Posts

<?php
header('content-type: image/jpeg');
$watermark = imagecreatefrompng('hello.png');  

$watermark_width = imagesx($watermark);  
$watermark_height = imagesy($watermark);  
$image = imagecreatetruecolor($watermark_width, $watermark_height);  
$image = imagecreatefromjpeg('notebook.jpg');  
$size = getimagesize('notebook.jpg');  
$dest_x = $size[0] - $watermark_width - 5;  
$dest_y = $size[1] - $watermark_height - 5;  
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);  
imagejpeg($image, "hihi.jpg");  


?>

I need the hello.png to be the watermark for notebook.jpg. The code merge both photo together, but the hello.png appear to be total black. Can I know why is that so?

I just replied to a post like this, but here is an easy way to do it. It is a function that I created:

 

http://phpsnips.com/snippet.php?id=105

 

It has support for these types of positioning:

TOP_LEFT

TOP_RIGHT

BOTTOM_LEFT

BOTTOM_RIGHT

CENTER

 

It also has support for exact pixel x, y positioning.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.