【php】图像处理函数

[php] view plain copy
 
  1.     php提供了丰富的图像处理函数,主要包括如下几种:  
  2.   
  3.     ①获取图像信息的函数  
  4.     ②创建与销毁图像的函数  
  5.     ③载入图像的函数  
  6.     ④输出图像的函数  
  7.     ⑤分配/取消图像颜色的函数  
  8.     ⑥拷贝图像的函数  
  9.     ⑦合并图像的函数  
  10.     ⑧绘制线段与圆弧的函数  
  11.     ⑨图像填充函数  
  12.   
  13.     在使用php的图像处理函数之前,需要开启php.ini中的gd2库扩展  
  14.       
  15.     extension=php_gd2.dll     
  16.   
  17. 使用gd_info()函数可以查看当前安装的gd库信息:  
  18.     <?php  
  19.     var_dump(gd_info());  
  20.     ?>  
  21.   
  22. 结果:  
  23. array(12) {  
  24.     ["GD Version"]=>  
  25.     string(27) "bundled (2.0.34 compatible)"  
  26.     ["FreeType Support"]=>  
  27.     bool(true)  
  28.     ["FreeType Linkage"]=>  
  29.     string(13) "with freetype"  
  30.     ["T1Lib Support"]=>  
  31.     bool(true)  
  32.     ["GIF Read Support"]=>  
  33.     bool(true)  
  34.     ["GIF Create Support"]=>  
  35.     bool(true)  
  36.     ["JPG Support"]=>  
  37.     bool(true)  
  38.     ["PNG Support"]=>  
  39.     bool(true)  
  40.     ["WBMP Support"]=>  
  41.     bool(true)  
  42.     ["XPM Support"]=>  
  43.     bool(false)  
  44.     ["XBM Support"]=>  
  45.     bool(true)  
  46.     ["JIS-mapped Japanese Font Support"]=>  
  47.     bool(false)  
  48. }  
  49.   
  50.   
  51.     常用函数:  
  52.   
  53. (1)getimagesize():此函数主要用于获取图像的大小及相关信息,成功则返回一个数组,失败则返回false  
  54.     语法:  
  55.         array getimagesize(string filename);  
  56. 案例:  
  57.     <?php  
  58.     $array = getimagesize("images/flower_1.jpg");  
  59.     print_r($array);  
  60.     ?>  
  61.   
  62. 结果:  
  63. 浏览器中的结果:  
  64. Array  
  65. (  
  66.     [0] => 350  
  67.     [1] => 318  
  68.     [2] => 2  
  69.     [3] => width="350" height="318"  
  70.     [bits] => 8  
  71.     [channels] => 3  
  72.     [mime] => image/jpeg  
  73. )  
  74.   
  75. 返回结果说明  
  76.     ①索引 0 给出的是图像宽度的像素值  
  77.     ②索引 1 给出的是图像高度的像素值  
  78.     ③索引 2 给出的是图像的类型,返回的是数字,其中1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC,10 = JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM  
  79.     ④索引 3 给出的是一个宽度和高度的字符串,可以直接用于 HTML 的 <image> 标签  
  80.     ⑤索引 bits 给出的是图像的每种颜色的位数,二进制格式  
  81.     ⑥索引 channels 给出的是图像的通道值,RGB 图像默认是 3  
  82.     ⑦索引 mime 给出的是图像的 MIME 信息,此信息可以用来在 HTTP Content-type 头信息中发送正确的信息,  
  83.         如: header("Content-type: image/jpeg");   
  84.   
  85. (2)imagesx(),imagesy():这两个函数分别用来获取图像的宽度和高度,单位为像素,返回值为整型  
  86.     语法:  
  87.         int imagesx(resource image)  
  88.         int imagesy(resource image)  
  89.     注意:  
  90.     参数为如 imagecreatetruecolor()、imagecreatefromjpeg() 等函数返回的图像资源  
  91. 案例:  
  92.     <?php  
  93.     $img = imagecreatefromjpeg("images/flower_1.jpg");  
  94.     echo "图像宽度:",imagesx( $img ),"<br />";  
  95.     echo "图像高度:",imagesy( $img );  
  96.     ?>  
  97.   
  98. 浏览器输出:   
  99.   
  100. 图像宽度:350  
  101. 图像高度:318  
  102.   
  103.   
  104. (3)如果我们要对图像进行处理,就如其它图像处理软件一样,需要创建一块画布。  
  105.     imagecreate()与imagecreatetruecolor()函数用于创建一幅空白图像  
  106.     语法:  
  107.         resource   imagecreate(int x,int y)  
  108.     注意:参数x、y分别代表要创建图像的宽度和高度,返回一个图像资源  
  109. 案例:  
  110. <?  
  111. header("Content-type: image/png");  
  112. //创建图像  
  113. $im = @imagecreate(200, 50) or die("创建图像资源失败");  
  114. //图片背景颜色  
  115. $bg = imagecolorallocate($im, 255, 255, 255);  
  116. //文字颜色  
  117. $text_color = imagecolorallocate($im, 0, 0, 255);  
  118. //水平画一行字,要输出中文等需要 TTF 字体支持的请使用 magettftext() 函数  
  119. imagestring($im, 5, 0, 0, "Hello world!", $text_color);  
  120. //以PNG格式输出图像  
  121. imagepng($im);  
  122. //销毁图像资源  
  123. imagedestroy($im);  
  124. ?>  
  125.   
  126. (4)图像处理完成后,使用imagedestroy()函数销毁图像资源以释放内存  
  127.     语法:  
  128.         bool   imagedestroy(resource image)  
  129.   
  130. (5)此系列函数用于从文件或url载入一张图像,成功返回一个图像资源,失败返回一个空字符串  
  131. 该系列函数有:  
  132.     ①imagecreatefromgif():创建一块画布,并从 GIF 文件或 URL 地址载入一副图像  
  133.     ②imagecreatefromjpeg():创建一块画布,并从 JPEG 文件或 URL 地址载入一副图像  
  134.     ③imagecreatefrompng():创建一块画布,并从 PNG 文件或 URL 地址载入一副图像  
  135.     ④imagecreatefromwbmp()创建一块画布并从 WBMP 文件或 URL 地址载入一副图像  
  136.     ⑤imagecreatefromstring():创建一块画布,并从字符串中的图像流新建一副图像  
  137. 语法:  
  138.     ①resource imagecreatefromgif( string filename )  
  139.     ②resource imagecreatefromjpeg( string filename )  
  140.     ③resource imagecreatefrompng( string filename )  
  141.     ④resource imagecreatefromwbmp( string filename )  
  142.     ⑤resource imagecreatefromstring( string image )  
  143.   
  144. (6)载入图像案例:  
  145. <?  
  146. header("Content-type: image/jpeg");  
  147. //创建并载入一幅图像  
  148. $im = @imagecreatefromjpeg("images/flower_1.jpg");  
  149. //错误处理  
  150. if(!$im){  
  151.     $im  = imagecreatetruecolor(150, 30);  
  152.     $bg = imagecolorallocate($im, 255, 255, 255);  
  153.     $text_color  = imagecolorallocate($im, 0, 0, 255);  
  154.     //填充背景色  
  155.     imagefilledrectangle($im, 0, 0, 150, 30, $bg);  
  156.     //以图像方式输出错误信息  
  157.     imagestring($im, 3, 5, 5, "Error loading image", $text_color);  
  158. else {  
  159.     //输出该图像  
  160.     imagejpeg($im);  
  161. }  
  162. ?>  
  163.   
  164. 此系列函数主要用于以不同格式将图像输出到浏览器或文件  
  165. php允许将图像以不同格式输出,该系列函数有:  
  166.     ①imagegif():以 GIF 格式将图像输出到浏览器或文件  
  167.     ②imagejpeg():以 JPEG 格式将图像输出到浏览器或文件  
  168.     ③imagepng():以 PNG 格式将图像输出到浏览器或文件  
  169.     ④imagewbmp():以 WBMP 格式将图像输出到浏览器或文件  
  170. 语法:  
  171.     ①bool imagegif ( resource image [, string filename] )  
  172.     ②bool imagejpeg ( resource image [, string filename [, int quality]] )  
  173.     ③bool imagepng ( resource image [, string filename] )  
  174.     ④bool imagewbmp ( resource image [, string filename [, int foreground]] )  
  175.   
  176. <img src="//img-my.csdn.net/uploads/201209/16/1347794010_6339.png" alt="">  
[php] view plain copy
 
  1. 绘制一个圆弧并保存到image目录下:  
  2. <?php  
  3. header("Content-type: image/png");  
  4. $im = @imagecreate(200, 200)or die("创建图像资源失败");  
  5. $bg = imagecolorallocate($im, 204, 204, 204);  
  6. $red = imagecolorallocate($im, 255, 0, 0);  
  7. imagearc($im, 100, 100, 150, 150, 0, 360, $red);  
  8. imagepng($im,"images/circle.png");  
  9. imagedestroy($im);  
  10. ?>  
  11. 在 images 目录下就会生成一个 circle.png 文件。  
  12.   
  13. (7)imagecolorallocate() 函数用于为图像分配颜色,返回一个标识符,代表了由给定的 RGB 成分组成的颜色,如果分配失败则返回 -1  
  14.     语法:  
  15.         int imagecolorallocate( resource image, int red, int green, int blue )  
  16.     注意:  
  17.         参数 red,green 和 blue 分别是所需要的颜色的 红,绿,蓝 成分,取值范围 0 - 255  
  18.   
  19. imagecolorallocatealpha()和 imagecolorallocate() 用法相同,但多了一个额外的透明度参数 alpha,其值从 0 到 127。0 表示完全不透明,127 表示完全透明  
  20.     语法:  
  21.         int imagecolorallocatealpha( resource image, int red, int green, int blue, int alpha )  
  22.   
  23.   
  24.   
  25.   
  26. 分配图像颜色案例:  
  27.      <?php  
  28. header("Content-type: image/png");  
  29. //创建图像  
  30. $im = @imagecreate(200, 50) or die("创建图像资源失败");  
  31. //图片背景颜色并填充  
  32. $bg = imagecolorallocate($im, 204, 204, 204);  
  33. //设定文字颜色  
  34. $red = imagecolorallocate($im, 255, 0, 0);  
  35. //水平画一行字  
  36. imagestring($im, 5, 0, 0, "Hello world!", $red);  
  37. //以PNG格式输出图像  
  38. imagepng($im);  
  39. //销毁图像资源  
  40. imagedestroy($im);  
  41. ?>  
  42.   
  43. (8)imagecolordeallocate() 函数用于取消先前由 imagecolorallocate() 和imagecolorallocatealpha() 函数为图像分配的颜色。   
  44.     语法:  
  45.         bool imagecolordeallocate( resource image, int color )  
  46.   
  47. 案例:  
  48.       
  49.     <?  
  50.     $im = @imagecreate(200, 50) or die("创建图像资源失败");  
  51.     $bg = imagecolorallocate($im, 255, 0, 0);  
  52.     imagecolordeallocate($im, $bg);  
  53.     ?>  
  54.   
  55. imagecopy() 函数用于拷贝图像或图像的一部分,成功返回 true,否则返回 false    
  56.     语法:  
  57.         bool imagecopy( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y,int src_w, int src_h )  
  58.   
  59.   
  60. <img src="//img-my.csdn.net/uploads/201209/16/1347794022_2695.png" alt="">  
[php] view plain copy
 
  1. imagecopy() 函数案例:  
  2.   
  3.       <?php  
  4. header("Content-type: image/jpeg");  
  5. //创建目标图像  
  6. $dst_im = imagecreatetruecolor(150, 150);  
  7. //源图像  
  8. $src_im = @imagecreatefromjpeg("images/flower_1.jpg");  
  9. //拷贝源图像左上角起始 150px 150px  
  10. imagecopy( $dst_im, $src_im, 0, 0, 0, 0, 150, 150 );  
  11. //输出拷贝后图像  
  12. imagejpeg($dst_im);  
  13. imagedestroy($dst_im);  
  14. imagedestroy($src_im);  
  15. ?>  
  16.   
  17. (9)imagecopyresized() 函数用于拷贝图像或图像的一部分并调整大小,成功返回 true ,否则返回 false  
  18.   
  19.     语法:  
  20.         bool imagecopyresized( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y,int dst_w, int dst_h, int src_w, int src_h )  
  21.        
  22.         本函数参数可参看 imagecopy() 函数,只是本函数增加了两个参数(注意顺序):   
  23.         1.dst_w:目标图像的宽度。  
  24.         2.dst_h:目标图像的高度。  
  25.   
  26. imagecopyresized() 生成图片缩略图案例:  
  27. <?php  
  28. header("Content-type: image/jpeg");  
  29. //原图文件  
  30. $file = "images/flower_1.jpg";  
  31. // 缩略图比例  
  32. $percent = 0.5;  
  33. // 缩略图尺寸  
  34. list($width, $height) = getimagesize($file);  
  35. $newwidth = $width * $percent;  
  36. $newheight = $height * $percent;  
  37. // 加载图像  
  38. $src_im = @imagecreatefromjpeg($file);  
  39. $dst_im = imagecreatetruecolor($newwidth, $newheight);  
  40. // 调整大小  
  41. imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);  
  42. //输出缩小后的图像  
  43. imagejpeg($dst_im);  
  44. imagedestroy($dst_im);  
  45. imagedestroy($src_im);  
  46. ?>  
  47.   
  48. (10)imagecopymerge() 函数用于拷贝并合并图像的一部分,成功返回 true ,否则返回 false  
  49.     语法:  
  50.         bool imagecopymerge( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y,int src_w, int src_h, int pct )  
  51.   
  52.   
  53. <img src="//img-my.csdn.net/uploads/201209/16/1347794029_9965.png" alt="">  
[php] view plain copy
 
  1. 注意:当为 pct = 100 时对于调色板图像本函数和 imagecopy() 完全一样  
  2.   
  3. imagecopymerge() 函数实现水印功能:  
  4. <?php  
  5. header("Content-type: image/jpeg");  
  6. //原始图像  
  7. $dst = "images/flower_1.jpg";  
  8. //得到原始图片信息  
  9. $dst_im = imagecreatefromjpeg($dst);  
  10. $dst_info = getimagesize($dst);  
  11. //水印图像  
  12. $src = "images/logo.gif";  
  13. $src_im = imagecreatefromgif($src);  
  14. $src_info = getimagesize($src);   
  15. //水印透明度  
  16. $alpha = 30;  
  17. //合并水印图片  
  18. imagecopymerge($dst_im,$src_im,$dst_info[0]-$src_info[0],$dst_info[1]-$src_info[1],0,0,$src_info[0],  
  19. $src_info[1],$alpha);  
  20. //输出合并后水印图片  
  21. imagejpeg($dst_im);  
  22. imagedestroy($dst_im);  
  23. imagedestroy($src_im);  
  24. ?>  

 

[php] view plain copy
 
  1. (11)imageline() 函数用于绘制一条线段。  
  2.     语法:  
  3.         bool imageline( resource image, int x1, int y1, int x2, int y2, int color )  
  4.     注意:  
  5.         用 color 颜色在图像 image 中从坐标 x1,y1 到 x2,y2(图像左上角坐标为 0,0)画一条线段。  
  6. 案例:  
  7. <?php  
  8. header("Content-type: image/png");  
  9. $im = @imagecreate(300, 300)or die("创建图像资源失败");  
  10. $bg = imagecolorallocate($im, 204, 204, 204);  
  11. $red = imagecolorallocate($im, 255, 0, 0);  
  12. imageline($im,0,30,200,30,$red);  
  13. imagepng($im);  
  14. imagedestroy($im);  
  15. ?>  
  16.   
  17. (12)imagesetstyle() 设定所有画线的函数(例如 imageline() 和 imagepolygon())在使用特殊颜色 IMG_COLOR_STYLED 或者用 IMG_COLOR_STYLEDBRUSHED 画一行图像时所使用的风格。如果成功则返回 TRUE ,失败则返回 FALSE   
  18.     语法:  
  19.         bool imagesetstyle( resource image, array style )  
  20.     注意:style 参数是像素组成的数组。  
  21. 案例:  
  22. <?php  
  23. header("Content-type: image/png");  
  24. $im = @imagecreate(300, 50)or die("创建图像资源失败");  
  25. $bg = imagecolorallocate($im, 204, 204, 204);  
  26. $red = imagecolorallocate($im, 255, 0, 0);  
  27. // 画一条虚线,5 个红色像素,4 个背景像素  
  28. $style = array($red, $red, $red, $red, $red, $bg, $bg, $bg, $bg);  
  29. imagesetstyle($im, $style);  
  30. imageline($im, 0, 20, 200, 20, IMG_COLOR_STYLED);  
  31. imagepng($im);  
  32. imagedestroy($im);  
  33. ?>  
  34.   
  35. (13)imagearc() 函数用于绘制椭圆弧(包括圆弧)。   
  36.   
  37.     语法:  
  38.         bool imagearc(resource image, int cx, int cy, int w, int h, int s, int e, int color )  
  39.   
  40.   
  41. <img src="//img-my.csdn.net/uploads/201209/16/1347794037_2828.png" alt="">  
[php] view plain copy
 
  1. imagearc() 函数用于绘制椭圆弧案例:  
  2.   
  3. <?php  
  4. header("Content-type: image/png");  
  5. $im = @imagecreate(200, 200)or die("创建图像资源失败");  
  6. $bg = imagecolorallocate($im, 204, 204, 204);  
  7. $red = imagecolorallocate($im, 255, 0, 0);  
  8. imagearc($im, 100, 100, 150, 150, 0, 360, $red);  
  9. imagepng($im);  
  10. imagedestroy($im);  
  11. ?>  
  12.   
  13.   
  14. (14)imagefill() 函数用于区域填充  
  15.     语法:  
  16.         bool imagefill( resource image, int x, int y, int color )  
  17.     注意:  
  18.         x,y 分别为填充的起始 x 坐标和 y 坐标,与 x, y 点颜色相同且相邻的点都会被填充。  
  19.   
  20. 案例:  
  21. <?php  
  22. header("Content-type: image/png");  
  23. $im = @imagecreatetruecolor(200, 200);  
  24. $red = imagecolorallocate($im, 255, 0, 0);  
  25. //用 $red 颜色填充图像  
  26. imagefill( $im, 0, 0, $red );  
  27. imagepng($im);  
  28. imagedestroy($im);  
  29. ?>  
  30.   
  31. (15)imagefilledarc() 函数画一椭圆弧并填充  
  32.     语法:  
  33.         bool imagefilledarc( resource image, int cx, int cy, int w, int h, int s, int e, int color, int style )  
  34.     注意:  
  35.         该函数参数用法可参考绘制椭圆弧函数 imagearc() ,只是本函数增加 style 参数表示填充方式  
  36.   
  37.   
  38. <img src="//img-my.csdn.net/uploads/201209/16/1347794045_2591.png" alt="">  
[php] view plain copy
 
  1. imagefilledarc() 使用案例:  
  2.   
  3. <?php  
  4. header('Content-type: image/png');  
  5. $im = imagecreatetruecolor(100, 100);  
  6. $red = imagecolorallocate($im, 255, 0, 0);  
  7. imagefilledarc($im, 50, 50, 100, 50, 0, 360 , $red, IMG_ARC_PIE);  
  8. imagepng($im);  
  9. imagedestroy($im);  
  10. ?>  
  11.   
  12. (16)imagefilledrectangle() 函数画一矩形并填充。  
  13.     语法:  
  14.         bool imagefilledrectangle( resource image, int x1, int y1, int x2, int y2, int color )  
  15.     注意:  
  16.         x1,y1为左上角左边,x2,y2为右下角坐标。  
  17. 案例:  
  18.     <?php  
  19.     header('Content-type: image/png');  
  20.     $im = imagecreatetruecolor(200, 200);  
  21.     $yellow = imagecolorallocate($im, 255, 255, 0);  
  22.     imagefilledrectangle($im, 20, 150, 40, 200, $yellow);  
  23.     imagefilledrectangle($im, 50, 80, 70, 200, $yellow);  
  24.     imagepng($im);  
  25.     imagedestroy($im);  
  26.     ?>  
  27.   
  28. (17)imagefilledpolygon() 函数画一多边形并填充。  
  29.     语法:  
  30.         bool imagefilledpolygon( resource image, array points, int num_points, int color )  
  31.   
  32.   
  33. <img src="//img-my.csdn.net/uploads/201209/16/1347794059_1534.png" alt="">  
[php] view plain copy
 
    1. 绘制一个用红色填充的六边形案例:  
    2.     <?php  
    3.     header('Content-type: image/png');  
    4.     $points = array(  
    5.             50, 50, // Point 1 (x, y)  
    6.             100, 50,    // Point 2 (x, y)  
    7.             150, 100,   // Point 3 (x, y)  
    8.             150, 150,   // Point 4 (x, y)  
    9.             100, 150,   // Point 5 (x, y)  
    10.             50, 100 // Point 6 (x, y)  
    11.        );  
    12.     $im = imagecreatetruecolor(200, 200);  
    13.     $red = imagecolorallocate($im, 255, 0, 0);  
    14.     imagefilledpolygon($im, $points, 6, $red);  
    15.     imagepng($im);  
    16.     imagedestroy($im);  
    17.     ?>  
    18.   
    19.   
    20.     问题?  
    21.   
    22. 如何创建缩略图?  
    23.   
    24.     创建一个基本的缩略图需要以下5个步骤:  
    25.     ①将源图像装载到一个php变量中  
    26.     ②确定原有图像的高度和宽度  
    27.     ③创建一个具有正确尺寸的空白缩略图  
    28.     ④复制原有图像到空白缩略图  
    29.     ⑤使用正确的内容类型显示缩略图  
    30.       
    31.       
    32.       
    33.     案例:  
    34.     <?php  
    35.     $sourceimage="images/1.jpg";  
    36.     $original=imagecreatefromjpeg($sourceimage);        //将源图像载入带一个php变量中  
    37.     $dims=getimagesize($sourceimage);               //返回图像的宽度和高度  
    38.       
    39.     $thumbwidth=200;                                //指定缩略图宽度  
    40.     $thumbheight=200;                               //指定缩略图高度  
    41.       
    42.     $thumb=imagecreatetruecolor($thumbwidth,$thumbheight);  //创建一个指定宽度和高度的空白图像,缩略图将被放置在其中  
    43.       
    44.     //此函数将图像的一个调整大小后的版本放置到空白缩略图中  
    45.     $imagecopyresampled($thumb,$original,0,0,0,0,$thumbwidth,$thumbheight,$dims[0],$dims[1]);//通过此函数生成缩略图  
    46.       
    47.     header("content-type:image/jpeg");              //通过header()函数定义输出的内容类型头  
    48.     imagejpeg($thumb);                          //使用imagejpeg()函数输出完成的缩略图  
    49.     imagedestroy($thumb);                           //销毁缩略图所占资源  
    50.     imagedestroy($original);                            //销毁源图所占资源  
    51.     ?>  
    52.       
    53.   
    54. 在gd2函数库中如何输出中文字符串?  
    55.   
    56.     php中的gd2库支持中文,但必须要以utf-8格式的参数来进行传递,如果使用imageString()函数直接绘制中文字符串就会显示乱码,这是因为gd2函数库对中文只能接受utf-8编码格式,并且默认使用了英文的字体,所以要输出中文字符串,就必须对中文字符串进行转码,并设置中文字符使用的字体,否则输出的只能是乱码  
    57.       
    58.     php在图像中添加中文字符串应用的是imagettftext()函数,  
    59.       
    60.     语法格式:  
    61.       
    62.     array imagettftext(resource image,float size,float angle,int x,int y, int color,string fontfile,string text);  
    63.       
    64.     参数1:图像资源  
    65.     参数2:字体大小  
    66.     参数3:字体的角度,顺时针计算,0度为水平,也就是3点钟的方向(由左到右),90度则为由下到上的文字  
    67.     参数4:文字的x坐标值  
    68.     参数5:文字的y坐标值  
    69.     参数6:文字的颜色  
    70.     参数7:字体的文件名称  
    71.     参数8:字符串内容  
    72.   
    73.     注意:imagettftext()函数只支持utf-8编码,所以在创建文件时必须也要使用utf-8编码格式,这样才能保证中文字符串的正常输出,但是如果页面本身使用的是gb2312编码格式,那么就需要使用iconv()函数对向图片中添加的中文字符串进行编码格式的转换,由gb2312编码转换为utf-8编码。  
    74.   
    75.   
    76. 如何应用gd2函数为图片添加图像水印?  
    77.   
    78.     使用图片作为水印的前提是该图片的背景必须是透明的,否则输出的效果将很不理想。  
    79.     图片水印添加的关键是getimagesize()和imagecopy()函数。应用getimagesize()函数获取上传图片和水印图片的大小,通过imagecopy()函数完成图片水印的添加  
    80.       
    81.     语法格式:  
    82.       
    83.     bool imagecopy(resource dst_im,resource src_im,int dst_x,int dst_y, int src_x ,int src_y,int src_w ,int src_h);  
    84.       
    85.     意义:将src_im图像中的坐标从src_x,src_y    开始,宽度为src_w,,高度为src_h的一部分复制到dst_im图像中坐标为dst_x,dst_y的位置上  
posted @ 2016-12-29 12:09  天涯海角路  阅读(184)  评论(0)    收藏  举报