GB2312.TXT Download: Download 1 Download 2 php / * --------------------------------- --------------------------------------- | Generate the picture class with watermark (support watermark Picture or text) | ================================================================================================================================================================================ Created on the basis of these friends' works) ------------------------------------------------------------------------------------------------------------------------------ ----------------------------------test:
$ img = new gimage (); $ IMG-> gburl = "inc /"; // 简体 中文 号 File Path // $ IMG-> WM_Text = "We are all Chinese"; $ img-> wm_text = "www .9cbs.net "; $ IMG-> WM_TEXT_FONT =" c: /windows/fonts/stxinwei.ttf "; // Font file path name file name / / $ IMG-> WM_IMAGE_NAME =" image / mouse.jpg " ; // Watermark picture, pay attention to include path name // $ IMG-> wm_text_size = 20; // Font size For text watermark $ IMG-> Create ("./ mouse.jpg"); * /
Class GIMAGE {VAR $ SRC_IMAGE_NAME = ""; // Enter the file name of the image (must include path name) var $ jpeg_quality = 60; // jpeg picture quality var $ save_file = ""; // Output file name var $ dstw = 1024; // Picture Output Maximum Width Var $ fsize = 307200; / / Picture Output Maximum Byte Var $ WM_IMAGE_NAME = ""; // Watermark Image file name (must include path name) VAR $ WM_IMAGE_POS = 3; // Watermark picture placement location // 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 // Other = 3 Var $ WM_IMAGE_TRANSITION = 80; // Watermark Image Follow the original picture (1 = 100) VAR $ GBURL = "./"; // Simplified Chinese code file Path VAR $ WM_TEXT = ""; // Watermark text (supporting Chinese and English, cross-line text with / R / N) var $ wm_text_size = 20; // Watermark text size var $ wm_text_angle = 5; // Watermark text angle, This value should not change the VAR $ WM_TEXT_POS = 3; // Watermark text Place position VAR $ wm_text_font = ""; // Watermark text Fonts Var $ WM_TEXT_COLOR = "#cccccc"; // Watermark font color value FUN ction create ($ filename = "") {if ($ filename) {$ this-> 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 = start (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, $ {$ 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_text_angle, $ wm_text_x, $ wm_text_y, $ wm_text_color, $ this-> wm_text_font, $ this-> wm_text);} / / Adjust size or size if ($ this-> dstw) {$ flag = 0; $ size = getImageSize; if ($ size [0]> $ this-> dstw) {// picture size is greater than limited size $ FLAG = 1; $ dsth = $ this-> DSTW / $ SIZE [0] * $ size [1];} else if ($ this-> fsize
ImageCreatetruecolor ($ THIS-> DSTW, $ DSTH); ImageCopyResized ($ DST_IMAGE, $ SRC_IMAGE, 0, 0, 0, 0, $ THIS-> DSTW, $ DSTH, $ SIZE [0], $ SIZE [1]); $ SRC_IMAGE = $ dst_image; unset ($ dst_image);}}} ($ this-> save_file) {switch ($ this-> get_type ($ this-> save_file) {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;}} ($ src_image);} / * / * CREATEIMAGE Create a picture Internal function $ TYPE: Picture, including GIF, JPG, PNG $ IMG_NAME : Image file name, including path name, for example, "./mouse.jpg" * / Function CreateImage ($ TY, $ 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 generates the internal function of the watermark in the source image according to the length, wide, position code, and watermark image ID of the source image. SourceFile_Width: Source Image Width $ SourceFile_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, $ SOUREFILE_HEIGHT, $ POS, $ WM_IMAGE = "") {IF ( $ WM_IMAGE) {$ INSERTFILE_WIDTH = Imagesx ($ WM_IM age); $ insertfile_height = ImageSy ($ wm_image);} else {$ lineCount = explode ( "/ r / n", $ this-> wm_text); $ fontSize = imagettfbbox ($ this-> wm_text_size, $ this-> wm_text_angle $ this-> wm_text_font, $ this-> wm_text); $ INSERTFILE_WIDTH = $ FONTSIZE [2] - $ FONTSIZE [0];
$ INSERTFILE_HEIGHT = Count ($ FONTSIZE [1] - $ FONTSIZE [3]);} Switch ($ POS) {Case 0: $ dest_x = ($ SOUREFILE_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 Specifies the text to UTF-8 format, including Chinese and English mixed internal functions * / function GB2UTF8 ($ GB) {if (! Trim ($ GB)) Return $ GB; $ filename = $ this-> gburl. "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 (Substr ($ GB, 0, 1))> 127) {$ TTHIS = SUBSTR ($ GB, 0, 2); $ GB = Substr ($ GB, 2, Strlen ($ 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); $ ST r. = 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] } Else {$ type = "string";}}}}}}?>