PageRenderTime 57ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Admin/Lib/ORG/Image.class.php

https://github.com/keheng/dwz_thinkphp
PHP | 538 lines | 338 code | 21 blank | 179 comment | 62 complexity | d2c449c3fcfa154163c9577694ba66ba MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. /**
  12. +------------------------------------------------------------------------------
  13. * 图像操作类库
  14. +------------------------------------------------------------------------------
  15. * @category ORG
  16. * @package ORG
  17. * @subpackage Util
  18. * @author liu21st <liu21st@gmail.com>
  19. * @version $Id$
  20. +------------------------------------------------------------------------------
  21. */
  22. class Image extends Think
  23. {//类定义开始
  24. /**
  25. +----------------------------------------------------------
  26. * 取得图像信息
  27. *
  28. +----------------------------------------------------------
  29. * @static
  30. * @access public
  31. +----------------------------------------------------------
  32. * @param string $image 图像文件名
  33. +----------------------------------------------------------
  34. * @return mixed
  35. +----------------------------------------------------------
  36. */
  37. static function getImageInfo($img) {
  38. $imageInfo = getimagesize($img);
  39. if( $imageInfo!== false) {
  40. $imageType = strtolower(substr(image_type_to_extension($imageInfo[2]),1));
  41. $imageSize = filesize($img);
  42. $info = array(
  43. "width"=>$imageInfo[0],
  44. "height"=>$imageInfo[1],
  45. "type"=>$imageType,
  46. "size"=>$imageSize,
  47. "mime"=>$imageInfo['mime']
  48. );
  49. return $info;
  50. }else {
  51. return false;
  52. }
  53. }
  54. /**
  55. +----------------------------------------------------------
  56. * 显示服务器图像文件
  57. * 支持URL方式
  58. +----------------------------------------------------------
  59. * @static
  60. * @access public
  61. +----------------------------------------------------------
  62. * @param string $imgFile 图像文件名
  63. * @param string $text 文字字符串
  64. * @param string $width 图像宽度
  65. * @param string $height 图像高度
  66. +----------------------------------------------------------
  67. * @return void
  68. +----------------------------------------------------------
  69. */
  70. static function showImg($imgFile,$text='',$width=80,$height=30) {
  71. //获取图像文件信息
  72. $info = Image::getImageInfo($imgFile);
  73. if($info !== false) {
  74. $createFun = str_replace('/','createfrom',$info['mime']);
  75. $im = $createFun($imgFile);
  76. if($im) {
  77. $ImageFun= str_replace('/','',$info['mime']);
  78. if(!empty($text)) {
  79. $tc = imagecolorallocate($im, 0, 0, 0);
  80. imagestring($im, 3, 5, 5, $text, $tc);
  81. }
  82. if($info['type']=='png' || $info['type']=='gif') {
  83. imagealphablending($im, false);//取消默认的混色模式
  84. imagesavealpha($im,true);//设定保存完整的 alpha 通道信息
  85. }
  86. header("Content-type: ".$info['mime']);
  87. $ImageFun($im);
  88. imagedestroy($im);
  89. return ;
  90. }
  91. }
  92. //获取或者创建图像文件失败则生成空白PNG图片
  93. $im = imagecreatetruecolor($width, $height);
  94. $bgc = imagecolorallocate($im, 255, 255, 255);
  95. $tc = imagecolorallocate($im, 0, 0, 0);
  96. imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
  97. imagestring($im, 4, 5, 5, "NO PIC", $tc);
  98. Image::output($im);
  99. return ;
  100. }
  101. /**
  102. +----------------------------------------------------------
  103. * 生成缩略图
  104. +----------------------------------------------------------
  105. * @static
  106. * @access public
  107. +----------------------------------------------------------
  108. * @param string $image 原图
  109. * @param string $type 图像格式
  110. * @param string $thumbname 缩略图文件名
  111. * @param string $maxWidth 宽度
  112. * @param string $maxHeight 高度
  113. * @param string $position 缩略图保存目录
  114. * @param boolean $interlace 启用隔行扫描
  115. +----------------------------------------------------------
  116. * @return void
  117. +----------------------------------------------------------
  118. */
  119. static function thumb($image,$thumbname,$type='',$maxWidth=200,$maxHeight=50,$interlace=true)
  120. {
  121. // 获取原图信息
  122. $info = Image::getImageInfo($image);
  123. if($info !== false) {
  124. $srcWidth = $info['width'];
  125. $srcHeight = $info['height'];
  126. $type = empty($type)?$info['type']:$type;
  127. $type = strtolower($type);
  128. $interlace = $interlace? 1:0;
  129. unset($info);
  130. $scale = min($maxWidth/$srcWidth, $maxHeight/$srcHeight); // 计算缩放比例
  131. if($scale>=1) {
  132. // 超过原图大小不再缩略
  133. $width = $srcWidth;
  134. $height = $srcHeight;
  135. }else{
  136. // 缩略图尺寸
  137. $width = (int)($srcWidth*$scale);
  138. $height = (int)($srcHeight*$scale);
  139. }
  140. // 载入原图
  141. $createFun = 'ImageCreateFrom'.($type=='jpg'?'jpeg':$type);
  142. $srcImg = $createFun($image);
  143. //创建缩略图
  144. if($type!='gif' && function_exists('imagecreatetruecolor'))
  145. $thumbImg = imagecreatetruecolor($width, $height);
  146. else
  147. $thumbImg = imagecreate($width, $height);
  148. // 复制图片
  149. if(function_exists("ImageCopyResampled"))
  150. imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth,$srcHeight);
  151. else
  152. imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth,$srcHeight);
  153. if('gif'==$type || 'png'==$type) {
  154. //imagealphablending($thumbImg, false);//取消默认的混色模式
  155. //imagesavealpha($thumbImg,true);//设定保存完整的 alpha 通道信息
  156. $background_color = imagecolorallocate($thumbImg, 0,255,0); // 指派一个绿色
  157. imagecolortransparent($thumbImg,$background_color); // 设置为透明色,若注释掉该行则输出绿色的图
  158. }
  159. // 对jpeg图形设置隔行扫描
  160. if('jpg'==$type || 'jpeg'==$type) imageinterlace($thumbImg,$interlace);
  161. //$gray=ImageColorAllocate($thumbImg,255,0,0);
  162. //ImageString($thumbImg,2,5,5,"ThinkPHP",$gray);
  163. // 生成图片
  164. $imageFun = 'image'.($type=='jpg'?'jpeg':$type);
  165. $imageFun($thumbImg,$thumbname);
  166. imagedestroy($thumbImg);
  167. imagedestroy($srcImg);
  168. return $thumbname;
  169. }
  170. return false;
  171. }
  172. /**
  173. +----------------------------------------------------------
  174. * 根据给定的字符串生成图像
  175. +----------------------------------------------------------
  176. * @static
  177. * @access public
  178. +----------------------------------------------------------
  179. * @param string $string 字符串
  180. * @param string $size 图像大小 width,height 或者 array(width,height)
  181. * @param string $font 字体信息 fontface,fontsize 或者 array(fontface,fontsize)
  182. * @param string $type 图像格式 默认PNG
  183. * @param integer $disturb 是否干扰 1 点干扰 2 线干扰 3 复合干扰 0 无干扰
  184. * @param bool $border 是否加边框 array(color)
  185. +----------------------------------------------------------
  186. * @return string
  187. +----------------------------------------------------------
  188. */
  189. static function buildString($string,$rgb=array(),$filename='',$type='png',$disturb=1,$border=true) {
  190. if(is_string($size)) $size = explode(',',$size);
  191. $width = $size[0];
  192. $height = $size[1];
  193. if(is_string($font)) $font = explode(',',$font);
  194. $fontface = $font[0];
  195. $fontsize = $font[1];
  196. $length = strlen($string);
  197. $width = ($length*9+10)>$width?$length*9+10:$width;
  198. $height = 22;
  199. if ( $type!='gif' && function_exists('imagecreatetruecolor')) {
  200. $im = @imagecreatetruecolor($width,$height);
  201. }else {
  202. $im = @imagecreate($width,$height);
  203. }
  204. if(empty($rgb)) {
  205. $color = imagecolorallocate($im, 102, 104, 104);
  206. }else{
  207. $color = imagecolorallocate($im, $rgb[0], $rgb[1], $rgb[2]);
  208. }
  209. $backColor = imagecolorallocate($im, 255,255,255); //背景色(随机)
  210. $borderColor = imagecolorallocate($im, 100, 100, 100); //边框色
  211. $pointColor = imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)); //点颜色
  212. @imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
  213. @imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor);
  214. @imagestring($im, 5, 5, 3, $string, $color);
  215. if(!empty($disturb)) {
  216. // 添加干扰
  217. if($disturb=1 || $disturb=3) {
  218. for($i=0;$i<25;$i++){
  219. imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pointColor);
  220. }
  221. }elseif($disturb=2 || $disturb=3){
  222. for($i=0;$i<10;$i++){
  223. imagearc($im,mt_rand(-10,$width),mt_rand(-10,$height),mt_rand(30,300),mt_rand(20,200),55,44,$pointColor);
  224. }
  225. }
  226. }
  227. Image::output($im,$type,$filename);
  228. }
  229. /**
  230. +----------------------------------------------------------
  231. * 生成图像验证码
  232. +----------------------------------------------------------
  233. * @static
  234. * @access public
  235. +----------------------------------------------------------
  236. * @param string $length 位数
  237. * @param string $mode 类型
  238. * @param string $type 图像格式
  239. * @param string $width 宽度
  240. * @param string $height 高度
  241. +----------------------------------------------------------
  242. * @return string
  243. +----------------------------------------------------------
  244. */
  245. static function buildImageVerify($length=4,$mode=1,$type='png',$width=48,$height=22,$verifyName='verify')
  246. {
  247. import('@.ORG.String');
  248. $randval = String::rand_string($length,$mode);
  249. $_SESSION[$verifyName]= md5($randval);
  250. $width = ($length*10+10)>$width?$length*10+10:$width;
  251. if ( $type!='gif' && function_exists('imagecreatetruecolor')) {
  252. $im = @imagecreatetruecolor($width,$height);
  253. }else {
  254. $im = @imagecreate($width,$height);
  255. }
  256. $r = Array(225,255,255,223);
  257. $g = Array(225,236,237,255);
  258. $b = Array(225,236,166,125);
  259. $key = mt_rand(0,3);
  260. $backColor = imagecolorallocate($im, $r[$key],$g[$key],$b[$key]); //背景色(随机)
  261. $borderColor = imagecolorallocate($im, 100, 100, 100); //边框色
  262. $pointColor = imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)); //点颜色
  263. @imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
  264. @imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor);
  265. $stringColor = imagecolorallocate($im,mt_rand(0,200),mt_rand(0,120),mt_rand(0,120));
  266. // 干扰
  267. for($i=0;$i<10;$i++){
  268. $fontcolor=imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
  269. imagearc($im,mt_rand(-10,$width),mt_rand(-10,$height),mt_rand(30,300),mt_rand(20,200),55,44,$fontcolor);
  270. }
  271. for($i=0;$i<25;$i++){
  272. $fontcolor=imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
  273. imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pointColor);
  274. }
  275. for($i=0;$i<$length;$i++) {
  276. imagestring($im,5,$i*10+5,mt_rand(1,8),$randval{$i}, $stringColor);
  277. }
  278. // @imagestring($im, 5, 5, 3, $randval, $stringColor);
  279. Image::output($im,$type);
  280. }
  281. // 中文验证码
  282. static function GBVerify($length=4,$type='png',$width=180,$height=50,$fontface='simhei.ttf',$verifyName='verify') {
  283. $code = rand_string($length,4);
  284. $width = ($length*45)>$width?$length*45:$width;
  285. $_SESSION[$verifyName]= md5($code);
  286. $im=imagecreatetruecolor($width,$height);
  287. $borderColor = imagecolorallocate($im, 100, 100, 100); //边框色
  288. $bkcolor=imagecolorallocate($im,250,250,250);
  289. imagefill($im,0,0,$bkcolor);
  290. @imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor);
  291. // 干扰
  292. for($i=0;$i<15;$i++){
  293. $fontcolor=imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
  294. imagearc($im,mt_rand(-10,$width),mt_rand(-10,$height),mt_rand(30,300),mt_rand(20,200),55,44,$fontcolor);
  295. }
  296. for($i=0;$i<255;$i++){
  297. $fontcolor=imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
  298. imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$fontcolor);
  299. }
  300. if(!is_file($fontface)) {
  301. $fontface = dirname(__FILE__)."/".$fontface;
  302. }
  303. for($i=0;$i<$length;$i++){
  304. $fontcolor=imagecolorallocate($im,mt_rand(0,120),mt_rand(0,120),mt_rand(0,120)); //这样保证随机出来的颜色较深。
  305. $codex= msubstr($code,$i,1);
  306. imagettftext($im,mt_rand(16,20),mt_rand(-60,60),40*$i+20,mt_rand(30,35),$fontcolor,$fontface,$codex);
  307. }
  308. Image::output($im,$type);
  309. }
  310. /**
  311. +----------------------------------------------------------
  312. * 把图像转换成字符显示
  313. +----------------------------------------------------------
  314. * @static
  315. * @access public
  316. +----------------------------------------------------------
  317. * @param string $image 要显示的图像
  318. * @param string $type 图像类型,默认自动获取
  319. +----------------------------------------------------------
  320. * @return string
  321. +----------------------------------------------------------
  322. */
  323. static function showASCIIImg($image,$string='',$type='')
  324. {
  325. $info = Image::getImageInfo($image);
  326. if($info !== false) {
  327. $type = empty($type)?$info['type']:$type;
  328. unset($info);
  329. // 载入原图
  330. $createFun = 'ImageCreateFrom'.($type=='jpg'?'jpeg':$type);
  331. $im = $createFun($image);
  332. $dx = imagesx($im);
  333. $dy = imagesy($im);
  334. $i = 0;
  335. $out = '<span style="padding:0px;margin:0;line-height:100%;font-size:1px;">';
  336. set_time_limit(0);
  337. for($y = 0; $y < $dy; $y++) {
  338. for($x=0; $x < $dx; $x++) {
  339. $col = imagecolorat($im, $x, $y);
  340. $rgb = imagecolorsforindex($im,$col);
  341. $str = empty($string)?'*':$string[$i++];
  342. $out .= sprintf('<span style="margin:0px;color:#%02x%02x%02x">'.$str.'</span>',$rgb['red'],$rgb['green'],$rgb['blue']);
  343. }
  344. $out .= "<br>\n";
  345. }
  346. $out .= '</span>';
  347. imagedestroy($im);
  348. return $out;
  349. }
  350. return false;
  351. }
  352. /**
  353. +----------------------------------------------------------
  354. * 生成高级图像验证码
  355. +----------------------------------------------------------
  356. * @static
  357. * @access public
  358. +----------------------------------------------------------
  359. * @param string $type 图像格式
  360. * @param string $width 宽度
  361. * @param string $height 高度
  362. +----------------------------------------------------------
  363. * @return string
  364. +----------------------------------------------------------
  365. */
  366. static function showAdvVerify($type='png',$width=180,$height=40)
  367. {
  368. $rand = range('a','z');
  369. shuffle($rand);
  370. $verifyCode = array_slice($rand,0,10);
  371. $letter = implode(" ",$verifyCode);
  372. $_SESSION['verifyCode'] = $verifyCode;
  373. $im = imagecreate($width,$height);
  374. $r = array(225,255,255,223);
  375. $g = array(225,236,237,255);
  376. $b = array(225,236,166,125);
  377. $key = mt_rand(0,3);
  378. $backColor = imagecolorallocate($im, $r[$key],$g[$key],$b[$key]);
  379. $borderColor = imagecolorallocate($im, 100, 100, 100); //边框色
  380. imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
  381. imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor);
  382. $numberColor = imagecolorallocate($im, 255,rand(0,100), rand(0,100));
  383. $stringColor = imagecolorallocate($im, rand(0,100), rand(0,100), 255);
  384. // 添加干扰
  385. /*
  386. for($i=0;$i<10;$i++){
  387. $fontcolor=imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
  388. imagearc($im,mt_rand(-10,$width),mt_rand(-10,$height),mt_rand(30,300),mt_rand(20,200),55,44,$fontcolor);
  389. }
  390. for($i=0;$i<255;$i++){
  391. $fontcolor=imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
  392. imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$fontcolor);
  393. }*/
  394. imagestring($im, 5, 5, 1, "0 1 2 3 4 5 6 7 8 9", $numberColor);
  395. imagestring($im, 5, 5, 20, $letter, $stringColor);
  396. Image::output($im,$type);
  397. }
  398. /**
  399. +----------------------------------------------------------
  400. * 生成UPC-A条形码
  401. +----------------------------------------------------------
  402. * @static
  403. +----------------------------------------------------------
  404. * @param string $type 图像格式
  405. * @param string $type 图像格式
  406. * @param string $lw 单元宽度
  407. * @param string $hi 条码高度
  408. +----------------------------------------------------------
  409. * @return string
  410. +----------------------------------------------------------
  411. */
  412. static function UPCA($code,$type='png',$lw=2,$hi=100) {
  413. static $Lencode = array('0001101','0011001','0010011','0111101','0100011',
  414. '0110001','0101111','0111011','0110111','0001011');
  415. static $Rencode = array('1110010','1100110','1101100','1000010','1011100',
  416. '1001110','1010000','1000100','1001000','1110100');
  417. $ends = '101';
  418. $center = '01010';
  419. /* UPC-A Must be 11 digits, we compute the checksum. */
  420. if ( strlen($code) != 11 ) { die("UPC-A Must be 11 digits."); }
  421. /* Compute the EAN-13 Checksum digit */
  422. $ncode = '0'.$code;
  423. $even = 0; $odd = 0;
  424. for ($x=0;$x<12;$x++) {
  425. if ($x % 2) { $odd += $ncode[$x]; } else { $even += $ncode[$x]; }
  426. }
  427. $code.=(10 - (($odd * 3 + $even) % 10)) % 10;
  428. /* Create the bar encoding using a binary string */
  429. $bars=$ends;
  430. $bars.=$Lencode[$code[0]];
  431. for($x=1;$x<6;$x++) {
  432. $bars.=$Lencode[$code[$x]];
  433. }
  434. $bars.=$center;
  435. for($x=6;$x<12;$x++) {
  436. $bars.=$Rencode[$code[$x]];
  437. }
  438. $bars.=$ends;
  439. /* Generate the Barcode Image */
  440. if ( $type!='gif' && function_exists('imagecreatetruecolor')) {
  441. $im = imagecreatetruecolor($lw*95+30,$hi+30);
  442. }else {
  443. $im = imagecreate($lw*95+30,$hi+30);
  444. }
  445. $fg = ImageColorAllocate($im, 0, 0, 0);
  446. $bg = ImageColorAllocate($im, 255, 255, 255);
  447. ImageFilledRectangle($im, 0, 0, $lw*95+30, $hi+30, $bg);
  448. $shift=10;
  449. for ($x=0;$x<strlen($bars);$x++) {
  450. if (($x<10) || ($x>=45 && $x<50) || ($x >=85)) { $sh=10; } else { $sh=0; }
  451. if ($bars[$x] == '1') { $color = $fg; } else { $color = $bg; }
  452. ImageFilledRectangle($im, ($x*$lw)+15,5,($x+1)*$lw+14,$hi+5+$sh,$color);
  453. }
  454. /* Add the Human Readable Label */
  455. ImageString($im,4,5,$hi-5,$code[0],$fg);
  456. for ($x=0;$x<5;$x++) {
  457. ImageString($im,5,$lw*(13+$x*6)+15,$hi+5,$code[$x+1],$fg);
  458. ImageString($im,5,$lw*(53+$x*6)+15,$hi+5,$code[$x+6],$fg);
  459. }
  460. ImageString($im,4,$lw*95+17,$hi-5,$code[11],$fg);
  461. /* Output the Header and Content. */
  462. Image::output($im,$type);
  463. }
  464. // 生成手机号码
  465. static public function buildPhone() {
  466. }
  467. // 生成邮箱图片
  468. static public function buildEmail($email,$rgb=array(),$filename='',$type='png') {
  469. $mail = explode('@',$email);
  470. $user = trim($mail[0]);
  471. $mail = strtolower(trim($mail[1]));
  472. $path = dirname(__FILE__).'/Mail/';
  473. if(is_file($path.$mail.'.png')) {
  474. $im = imagecreatefrompng($path.$mail.'.png');
  475. $user_width = imagettfbbox(9, 0, dirname(__FILE__)."/Mail/tahoma.ttf", $user);
  476. $x_value = (200 - ($user_width[2] + 113));
  477. if(empty($rgb)) {
  478. $color = imagecolorallocate($im, 102, 104, 104);
  479. }else{
  480. $color = imagecolorallocate($im, $rgb[0], $rgb[1], $rgb[2]);
  481. }
  482. imagettftext($im, 9, 0, $x_value, 16, $color, dirname(__FILE__)."/Mail/tahoma.ttf", $user);
  483. }else{
  484. $user_width = imagettfbbox(9, 0, dirname(__FILE__)."/Mail/tahoma.ttf", $email);
  485. $width = $user_width[2]+15;
  486. $height = 20;
  487. $im = imagecreate($width,20);
  488. $backColor = imagecolorallocate($im, 255,255,255); //背景色(随机)
  489. $borderColor = imagecolorallocate($im, 100, 100, 100); //边框色
  490. $pointColor = imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)); //点颜色
  491. imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
  492. imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor);
  493. if(empty($rgb)) {
  494. $color = imagecolorallocate($im, 102, 104, 104);
  495. }else{
  496. $color = imagecolorallocate($im, $rgb[0], $rgb[1], $rgb[2]);
  497. }
  498. imagettftext($im, 9, 0, 5, 16, $color, dirname(__FILE__)."/Mail/tahoma.ttf", $email);
  499. for($i=0;$i<25;$i++){
  500. imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pointColor);
  501. }
  502. }
  503. Image::output($im,$type,$filename);
  504. }
  505. static function output($im,$type='png',$filename='')
  506. {
  507. header("Content-type: image/".$type);
  508. $ImageFun='image'.$type;
  509. if(empty($filename)) {
  510. $ImageFun($im);
  511. }else{
  512. $ImageFun($im,$filename);
  513. }
  514. imagedestroy($im);
  515. }
  516. }//类定义结束
  517. ?>