//Original image
- $dst = "/upload/20140914/20120914040740-0.jpg"; //Picture path
//Original picture 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 type 1") ;exit;
- }
- //Watermark image
- $src = "/images/shuiyin.png"; //Note that the path must be written correctly
- $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 type 1");exit;
- }
- //Semi-transparent format watermark
- //$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);
- //How to support the transparency of png itself
- 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 type 2");exit;
- }
//Destroy the gd library object
- imagedestroy($dst_im);
- imagedestroy($src_im);
Copy code
|