【php开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了php开源代码-Image.class.php的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
<?php
// +----------------------------------------------------------------------
// | ThinkPHP
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id$
/**
+------------------------------------------------------------------------------
* 鍥惧儚鎿嶄綔绫诲簱
+------------------------------------------------------------------------------
* @category ORG
* @package ORG
* @subpackage Util
* @author liu21st <liu21st@gmail.com>
* @version $Id$
+------------------------------------------------------------------------------
*/
class Image extends Base
{//绫诲畾涔夊紑濮?
/**
+----------------------------------------------------------
* 鍙栧緱鍥惧儚淇℃伅
*
+----------------------------------------------------------
* @static
* @access public
+----------------------------------------------------------
* @param string $image 鍥惧儚鏂囦欢鍚?
+----------------------------------------------------------
* @return mixed
+----------------------------------------------------------
*/
static function getImageInfo($img) {
$imageInfo = getimagesize($img);
if( $imageInfo!== false) {
$imageType = strtolower(substr(image_type_to_extension($imageInfo[2]),1));
$imageSize = filesize($img);
$info = array(
"width"=>$imageInfo[0],
"height"=>$imageInfo[1],
"type"=>$imageType,
"size"=>$imageSize,
"mime"=>$imageInfo['mime']
);
return $info;
}else {
return false;
}
}
/**
+----------------------------------------------------------
* 鏄剧ず鏈嶅姟鍣ㄥ浘鍍忔枃浠?
* 鏀寔URL鏂瑰紡
+----------------------------------------------------------
* @static
* @access public
+----------------------------------------------------------
* @param string $imgFile 鍥惧儚鏂囦欢鍚?
* @param string $text 鏂囧瓧瀛楃涓?
* @param string $width 鍥惧儚瀹藉害
* @param string $height 鍥惧儚楂樺害
+----------------------------------------------------------
* @return void
+----------------------------------------------------------
*/
static function showImg($imgFile,$text='',$width=80,$height=30) {
//鑾峰彇鍥惧儚鏂囦欢淇℃伅
$info = Image::getImageInfo($imgFile);
if($info !== false) {
$createFun = str_replace('/','createfrom',$info['mime']);
$im = $createFun($imgFile);
if($im) {
$ImageFun= str_replace('/','',$info['mime']);
if(!empty($text)) {
$tc = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 3, 5, 5, $text, $tc);
}
if($info['type']=='png' || $info['type']=='gif') {
imagealphablending($im, false);//鍙栨秷榛樿鐨勬贩鑹叉ā寮?
imagesavealpha($im,true);//璁惧畾淇濆瓨瀹屾暣鐨?alpha 閫氶亾淇℃伅
}
Header("Content-type: ".$info['mime']);
$ImageFun($im);
@ImageDestroy($im);
return ;
}
}
//鑾峰彇鎴栬呭垱寤哄浘鍍忔枃浠跺け璐ュ垯鐢熸垚绌虹櫧PNG鍥剧墖
$im = imagecreatetruecolor($width, $height);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
imagestring($im, 4, 5, 5, "NO PIC", $tc);
Image::output($im);
return ;
}
/**
+----------------------------------------------------------
* 鐢熸垚缂╃暐鍥?
+----------------------------------------------------------
* @static
* @access public
+----------------------------------------------------------
* @param string $image 鍘熷浘
* @param string $type 鍥惧儚鏍煎紡
* @param string $filename 缂╃暐鍥炬枃浠跺悕
* @param string $maxWidth 瀹藉害
* @param string $maxHeight 楂樺害
* @param string $position 缂╃暐鍥句繚瀛樼洰褰?
* @param boolean $interlace 鍚敤闅旇鎵弿
+----------------------------------------------------------
* @return void
+----------------------------------------------------------
* @throws ThinkExecption
+-----------------------------------------------