/ ************************************************** **********
********* Watermark start ********************************************* ****
****** 冲星 200 in 2004/10/04 *** Cold Spring *****************************
*******njj@nuc.edu.cn**************************************************** ***
**** Add the watermark function to the upload picture, ********************************
*********************************************************** ******** /
$ uPtypes = array ('image / jpg', 'image / jpeg', 'image / pjpeg', 'image / gif'); // Upload Image File Type List
$ wfile = "a.jpg"; // get the file path
$ WaterImg = "HQ.gif"; // Watermark Image Path
IF (In_Array ($ WFILE ['Type'], $ UPTYPES))
{// Check file type, if the uploaded file is a JPG or GIF picture, add watermark
IF (STRSTR ($ wfile ['type'], "jp")) {// If the upload picture type is JPG, PJPEG, JPEG, read the target file with ImageCreateFromJPEG
$ IM = ImageCreateFromJPEG ($ wfile);
$ wfilew = Imagesx ($ IM); // get the width of the picture
$ wfileh = imagesy ($ IM); // Get the highlight
} else {/ / Otherwise, if the image type is GIF, read the target file with ImageCreateFromGIF
$ IM = ImageCreateFromGIF ($ wfile);
$ wfilew = Imagesx ($ IM); // get the width of the picture
$ wfileh = imagesy ($ IM); // Get the highlight
}
/ / Set a mixed mode
ImageAlphablending ($ IM, TRUE);
// read watermark files
$ IM2 = ImageCreateFromgif ($ WaterIMG); // If the watermark picture is JPG, you can change it to $ IM2 = ImageCreateFromJPEG ($ WaterIMG)
$ Waterw = Imagesx ($ IM2); // Get the width of the watermark picture
$ Waterh = imagesy ($ IM2); // Get the high watermark picture
// randomly put water in the picture
$ randval = rand (0, 9); // Generate random number between 0-9
IF ($ randval == 0 || $ randval == 3 || $ randval == 2 || $ randval == 8 || $ randval == 7) {// This is also possible to improve more
$ WIMGX = 5; $ WIMGY = 5; // Put the upper corner
} else {
$ WIMGX = $ WFILEW-5- $ Waterw; $ WIMGY = $ WFILEH-5- $ Waterh; // Put the upper right corner
}
/ / Copy watermark to the target file
ImageCopy ($ IM, $ IM2, $ WIMGX, $ WIMGY, 0, 0, $ Waterw, $ Waterh);
// Output picture
IF (STRSTR ($ wfile ['type'], "jp")) {//
ImageJpeg ($ IM, $ WFILE);
} else {
Imagegif ($ IM, $ WFILE);
}
Imagedestroy ($ IM); ImageDestroy ($ IM2);
}
/ ************************************************** ***********
********* Watermark end ********************************************* *****
*********************************************************** ********* /