Copy codeThe Code is as follows: // the original image
$ Dst = "/upload/20120914/20120914040740 -0.jpg"; // ensure that the image path is correct.
// Obtain 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 type 1"); exit;
}
// Watermark image
$ Src = "/images/shuiyin.png"; // note that the path must be written
$ 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;
}
// Translucent 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 );
// Supports png 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 image
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;
}
Imagedestroy ($ dst_im );
Imagedestroy ($ src_im );