[Favorites] PHP adds watermarks to the picture

xiaoxiao2021-03-06  49

CODE:

src_image_name = strtolower (trim ($ filename)); $ src_image_type = $ this-> get_type ($ this-> src_image_name); $ src_image = $ this-> createImage ($ src_image_type, $ this-> src_image_name); if (! $ src_image) Return; $ src_image_w = imagesx ($ src_image); $ src_image_h = imagesy ($ src_image);

if ($ this-> wm_image_name) {$ this-> wm_image_name = strtolower (trim ($ this-> wm_image_name)); $ wm_image_type = $ this-> get_type ($ this-> wm_image_name); $ wm_image = $ this-> createImage ($ wm_image_type, $ this-> wm_image_name); $ wm_image_w = ImageSX ($ wm_image); $ wm_image_h = ImageSY ($ wm_image); $ temp_wm_image = $ this-> getPos ($ src_image_w, $ src_image_h, $ this-> wm_image_pos , $ wm_image); $ wm_image_x = $ temp_wm_image [ "dest_x"]; $ wm_image_y = $ temp_wm_image [ "dest_y"]; imageCopyMerge ($ src_image, $ wm_image, $ wm_image_x, $ wm_image_y, 0,0, $ wm_image_w, $ wm_image_h $ this-> wm_image_transition);} f ($ this-> wm_text) {$ this-> wm_text = $ this-> gb2utf8 ($ this-> wm_text); $ TEMP_WM_TEXT = $ THIS-> GetPOS ($ src_image_w, $ SRC_IMAGE_H, $ this-> wm_text_pos); $ wm_text_x = $ TEMP_WM_TEXT ["dest_x"]; $ wm_text_y = $ TEMP_WM_TEXT ["DEST_Y"]; if (preg_match ("/ ([A-F0-9] [A-F0- 9]) ([A-F0-9]) ([A-F0-9]) / I ", $ this-> wm_text_color, $ color)) { $ red = HEXDEC ($ Color [1]); $ Green = HEXDEC ($ Color [2]); $ blue = HEXDEC ($ Color [3]); $ wm_text_color = ImageColoralLocate ($ SRC_IMAGE, $ Red, $ Green, $ Blue) ;} else {$ wm_text_color = imagecolorallocate ($ src_image, 255,255,255);} imagettftext ($ src_image, $ this-> wm_text_size, $ this-> wm_angle, $ wm_text_x, $ wm_text_y, $ wm_text_color, $ this-> wm_text_font, $ this -> wm_text);} {Switch ($ this-> output_type) {case 'gif': $ src_img = imagepng ($ src_image, $ this-> save_file); Break; Case 'JPEG' : $ SRC_IMG =

ImageJPEG ($ src_image, $ this-> save_file, $ this-> jpeg_quality); break; case 'png': $ src_img = ImagePNG ($ src_image, $ this-> save_file); break; default: $ src_img = ImageJPEG ($ src_image, $ this-> save_file, $ this-> jpeg_quality); break;}} else {if ($ src_image_type = "jpg") $ src_image_type = "jpeg"; header ( "Content-type: image / {$ src_image_type} "); switch ($ src_image_type) {case 'gif': $ src_img = ImagePNG ($ src_image); break; case 'jpg': $ src_img = imageJPEG ($ src_image," ", $ this-> jpeg_quality); break; case 'png': $ src_img = ImagePNG ($ src_image); break; default: $ src_img = imageJPEG ($ src_image, "", $ this-> jpeg_quality); break;}} imagedestroy ($ src_image);} / * / * CREATEIMAGE Create a picture Internal function according to the file name and type, $ TYPE: Picture type, including GIF, JPG, PNG $ IMG_NAME: image file name, including path name, for example, "./mouse .jpg "* / Function CreateImage ($ TYPE, $ IMG_NAME) {IF (! $ type) {$ type = $ this-> get_type ($ IMG_NAME);} Switch ($ type) {case 'gif': IF (Function_exists ('imagecreatefromgif') $ TMP_IMG = @ ImageCreateFromGIF ($ IMG_NAME); Break; Case 'JPG': $ TMP_IMG = ImageCreateFromJPEG ($ IMG_NAME); Break;

Case 'PNG': $ TMP_IMG = ImageCreateFromPng ($ IMG_NAME); Break; Default: $ TMP_IMG = ImageCreateFromString ($ IMG_NAME); Break;} Return $ TMP_IMG;} / * GETPOS The length, wide, position code, and watermark image ID of the source image generates the inner function of the watermark to the source image. SourceFile_Width: Source Image WidgetFile_Height: Original image high $ POS: position code // 0 = middle // 1 = Top left // 2 = Top Right // 3 = bottom Right // 4 = bottom left // 5 = Top middle // 6 = middle right // 7 = bottom middle // 8 = middle left $ wm_image: watermark image ID * / function getPos ($ sourcefile_width, $ sourcefile_height, $ pos, $ wm_image = "") {if ($ wm_image) {$ insertfile_width = ImageSx ( $ WM_IMAGE); $ INSERTFILE_HEIGHT = ImageESY ($ WM_IMAGE);} else {$ linecount = expende ("/ r / n", $ this-> wm_text); $ fontsize = imagettfbbox ($ this-> wm_text_s ize, $ this-> wm_text_angle, $ this-> wm_text_font, $ this-> wm_text); $ insertfile_width = $ fontSize [2] - $ fontSize [0]; $ insertfile_height = count ($ lineCount) * ($ fontSize [1 ] - $ FONTSIZE [3]);} Switch ($ POS) {Case 0: $ dest_x =

($ SOURCEFILE_WIDTH / 2) - ($ INSERTFILE_WIDTH / 2); $ dest_y = ($ sourcefile_height / 2) - ($ INSERTFILE_HEIGHT / 2); Break; Case 1: $ dest_x = 0; if ($ this-> wm_text) { $ dest_y = $ insertfile_height;} else {$ dest_y = 0;} break; case 2: $ dest_x = $ sourcefile_width - $ insertfile_width; if ($ this-> wm_text) {$ dest_y = $ insertfile_height;} else {$ dest_y = 0;} break; case 3: $ dest_x = $ sourcefile_width - $ insertfile_width; $ dest_y = $ sourcefile_height - $ insertfile_height; break; case 4: $ dest_x = 0; $ dest_y = $ sourcefile_height - $ insertfile_height; Break; Case 5: $ dest_x = ($ SOURCEFILE_WIDTH - $ INSERTFILE_WIDTH) / 2); if ($ this-> wm_text) {$ dest_y = $ INSERTFILE_HEIGHT;} else {$ dest_y = 0;} Break; Case 6: $ dest_x = $ sourcefile_width - $ insertfile_width; $ dest_y = ($ sourcefile_height / 2) - ($ insertfile_height / 2); break; case 7: $ dest_x = (($ sourcefile_width - $ insertfile_width) / 2); $ dest_y = $ sourcefile_height $ INSERTFILE_HEIGHT;

break; case 8: $ dest_x = 0; $ dest_y = ($ sourcefile_height / 2) - ($ insertfile_height / 2); break; default: $ dest_x = $ sourcefile_width - $ insertfile_width; $ dest_y = $ sourcefile_height - $ insertfile_height; break } Return array ("dest_x" => $ dest_x, "dest_y" => $ dest_y);} / * GB2UTF8 Specified text is converted to UTF-8 format, Including Chinese and English Mixed Internal Functions * / Function GB2UTF8 ($ GB) {if (! Trim ($ GB)) Return $ GB; $ filename = "./ GB2312.TXT"; $ TMP = File ($ filename); $ CODETABLE = Array (); while (list ($ key, $ value) = Each ($ TMP)) $ CODETABLE [HEXDEC (Substr ($ Value, 0, 6))] = SUBSTR ($ Value, 7, 6); $ UTF8 = ""; While ($ GB) {IF (ORD (Substr ($ GB, 0, 1))> 127) {$ TTHIS = Substr ($ GB, 0, 2); $ GB = Substr ($ GB, 2, Strl EN ($ GB) -2); $ UTF8. = $ THIS-> U2UTF8 (HEXDEC ($ CODETABLE [HEXDEC (Bin2Hex ($ Tthis)) - 0x8080]));} else {$ TTHIS = SUBSTR ($ GB, 0 1); $ GB = SUBSTR ($ GB, 1, Strlen ($ GB) -1); $ UTF8. = $ THIS-> U2UTF8 ($ TTHIS);

}}} RETURN $ UTF8;} Function U2UTF8 ($ C) {$ Str = ""; if ($ C <0x80) {$ Str. = $ C;} else IF ($ c <0x800) {$ Str. = Chr (0xc0 | $ C >> 6); $ Str. = CHR (0x80 | $ C & 0x3f);} else IF ($ C <0x10000) {$ Str. = CHR (0xE0 | $ C >> 12); $ Str. = CHR (0x80 | $ C >> 6 & 0x3f); $ Str. = Chr (0x80 | $ C & 0x3f);} else IF ($ C <0x200000) {$ Str. = Chr (0xF0 | $ C >> 18); $ Str. = CHR (0x80 | $ C >> 12 & 0x3F); $ Str. = Chr (0x80 | $ C >> 6 & 0x3f); $ Str. = Chr (0x80 | $ C & C & 0x3f);} RETURN $ STR;} / * GET_TYPE Gets the format of the picture, including JPG, PNG, GIF internal function $ IMG_NAME: Image file name, can include path name * / function GET_TYPE ($ IMG_NAME) // Get image file type {$ Name_Array = EXPLODE (".", $ IMG_NAME); if (preg_match ("//. (jpg | jpeg | gif | png) $ /", $ IMG_NAME, $ Matches)) {$ TYPE = STRTOLOWER ($ matches [1]);} ELS e {$ TYPE = "string";}}}}}}?> How to use:

转载请注明原文地址:https://www.9cbs.com/read-110000.html

New Post(0)