php watermarked code of support translucent transparent watermarking support png transparent background
- 2020-05-27 04:39:15
- OfStack
// The original image
$dst = "/upload/20120914/20120914040740-0.jpg"; // Note that the picture path should be correct
// Get the original image information
$dst_info = getimagesize($dst);
switch ($dst_info[2])
{
case 1:
$dst_im =imagecreatefromgif($dst);break;
case 2:
$dst_im =imagecreatefromjpeg($dst);break;
case 3:
$dst_im =imagecreatefrompng($dst);break;
case 6:
$dst_im =imagecreatefromwbmp($dst);break;
default:
die(" Unsupported file types 1");exit;
}
// Watermark image
$src = "/images/shuiyin.png"; // Make sure you get the path right
$src_info = getimagesize($src);
switch ($src_info[2])
{
case 1:
$src_im =imagecreatefromgif($src);break;
case 2:
$src_im =imagecreatefromjpeg($src);break;
case 3:
$src_im =imagecreatefrompng($src);break;
case 6:
$src_im =imagecreatefromwbmp($src);break;
default:
die(" Unsupported file types 1");exit;
}
// Semi-transparent watermarking
//$alpha = 50;// Watermark transparency
//imagecopymerge($dst_im,$src_im,$dst_info[0]-$src_info[0]-10,$dst_info[1]-$src_info[1]-10,0,0,$src_info[0],$src_info[1],$alpha);
// support png Its own way of transparency
imagecopy($dst_im,$src_im,$dst_info[0]-$src_info[0]-10,$dst_info[1]-$src_info[1]-10,0,0,$src_info[0],$src_info[1]);
// Save the picture
switch ($dst_info[2]){
case 1:
imagegif($dst_im,$dst);break;
case 2:
imagejpeg($dst_im,$dst);break;
case 3:
imagepng($dst_im,$dst);break;
case 6:
imagewbmp($dst_im,$dst);break;
default:
die(" Unsupported file types 2");exit;
}
imagedestroy($dst_im);
imagedestroy($src_im);