複製程式碼 程式碼如下:
/*
*@author 夜無眠 27262681@qq.com
*copyright 27262681@qq.com
*copyright 27262681@qq.com
*copyright img {
function __construct($arg = null) {
$args = func_get_args(); }
$ this->im = call_user_func_array(array($this,'create'),$args);
}
function __call($func,$arg) { $funcstr = 'image'.$func;
} str = $func;
}else {
error( "沒有這個類別方法或函數");
}
return call_user_func_array($funcstr.建立影像
*@param string/ int 圖片檔案路徑或寬度
*@param int 高度,可省略
*@param string 6位元16進位整數
$args = func_get_args();
if(is_file($args[0])) {
$size = getimagesize($this->file ) or error('圖片類型錯誤');
$this->size = $this->size ? $this->size : $size; false );
$this->type = $this->type ? $this->type : $type;
$im = $createfunc($this ->file);
}elseif((int)$args[0]>0 and (int)$args[1]>0) {
,(int)$args[1]) or error("對不起,參數錯誤! ");
if(!$args[2]) {
imagecolortransparent($im,$color);
}else {
$color = hexdec(str_replace('#','',$args[2]));
}
int)$args[0] ,(int)$args[1]);
imagefill($im, 1, 1, $color); }
//imagealphablending($im,false);/ imageinterlace($im,true );//開啟隔行掃描
return $im;
}
/* *@param string/bool $color 可選,新圖片的背景色,false或空為透明
*@param bool $lashen 可選,是否拉伸,預設不拉伸
*/
function suolue($w = null,$h = null,$color = false,$lashen = false) {
> $h_o = imagesy($this->im);
if($w == null and $ 🎜> } elseif ($w != null and $h == null){
$h = $w * $h_o/$w_o; $im = $this->create($w,$h,$color);
$w_n = $w;
$h_n = $h; h) {
$h_n = $w*$h_o/$w_o;
$w_o/$h_o $w_n = $h*$w_o/$h_o;
🎜> if($lashen) {
$w_n = $w;
$h_n = $h;
> }
imagecopyresampled($im,$this->im,$ x,$y,0,0,$w_n,$h_n,$w_o,$h_o);
//imagedestroy($this->im); > return $im;
}
/*
*在圖片上寫字
*@param string $str 要寫的字串
左邊距離,right為右距離,left優先,top為距頂部距離,bottom為距底部距離,top優先;angle為角度,color為6位數16進位顏色,touming為文字透明度,font為字體文件
*/
function write($str = '' , $arg = array()) {
$size = $arg['size'] ? 20050; 🎜> $angle = $arg['angle'] ? $arg['angle'] : 0 ;
$color = $arg['color'] ? $arg['color'0 🎜> $touming = $arg['touming'] ? $arg['touming'] : 100;
) : 100;
)$10$1050000000000000000000000000000000000000000000000000000000) $color = hexdec ($touming.str_replace("#","",$color));
$font = $arg['font'] ? $arg['font'] : 'arial.ttf' boxarr = imagettfbbox($size,$angle,$font,$str);
$w = imagesx($this->im);
$x_l = $x_r = $boxarr[0];
$y_t = $y_b = $boxarr[1];
{
$x_l = $boxarr[$i] $x_r;
$y_t = $boxarr[$i+1] }
$width = $x_r - $ _l; $im = $this->create($width*4,$height*4);
$tm = hexdec('7fffffff');
imagettftext($im,$size, $angle,$width*2,$height*2,$color,$font,$str);
for($i=0;$i if(imagecolorat($im,$i,$ii) ! $x_l = $i;
break(2);
}
for($i=0;$i ;$ii if(imagecolorat($im,$ii,$i) ! $y_t = $i;
break(2 );
}
for($i=$width*4-1;$i>0;$i--) {
for($ii=$ 🎜> if(imagecolorat($im,$i,$ii) != $tm) {
規則(2);
}
} 0;$i--) {
for($ii=$x_ l; $ ii if(imagecolorat($im,$ii,$ y_b = $i;
規則(2);
}
) $y_off = $y_b - $height*2;
$width = $x_r - $x_l; //精確寬度
$height = $y_b - $y_t; // 精確高度
imagedestroy($im);
if(isset($arg['left'])) {
$x = (int)$arg['left'] - $x_off;
}elseif (isset($arg['right'])){
$x = $w - (int)$arg['right'] - $width - $woff -fff['right'] - $.
}else {
$x = ($w - $width)/2 - $x_off;
}
if(isset($arg['top'])) {
}elseif (isset($arg['bottom'])){
$y = $h - (int)$argarg['o_offbotd;
}else {
$y = ($h + $height)/2 - $y_off;
}
imagettftext($this->im,$size,$angle,$x,$y,$color,$font,$str);
返回 $this->im;
}
/*
*合併圖片(如圖片水影)
*@param string/resource $ 字元路徑或此符號圖片檔案路徑或此符號
function merge($file,$arg = array()) {
if(is_file($file)) {
}elseif(gettype($file)=='資源') {
$imc = $ $file;
}else {
error("無圖片");
}
$touming = $arg['touming'] ? (int)$arg['touming'] : 100 ;
$w = imagesx($this->im);
$h = imagesy($this->im);
$width = imagesx($imc);
$height = imagesy($imc);
if(isset($arg['left'])) {
$x = (int)$arg['left'];
}elseif (isset($arg['right'])){
$x = $w - (int)$arg['right'] - $widthth = $w - (int)$arg['right'] - $widthth;
}else {
$x = ($w - $width)/2;
}
if(isset($arg['top'])) {
}elseif (isset($arg['bottom'])){
$
}else {
$y = ($h - $height)/2;
}
imagecopymergegray($this->im,$imc,$x,$y,0,0,$width,$height,$touming);
}
/*
*輸出圖片
*@param string $type para liang jpeg圖片特有的,影像流程圖
*/
函數顯示($type = null,$filename = null,$zhiliang = null) {
$type = $this->類型?
}
if(($type == 'jpeg' or $type == 'jpg') and $zhiliang
$zhiliang = 100;
}
if($filename == null) {
}
$displayfunc = 'image'.$type;
$displayfunc($this->im,$filename,$zhiliang);
imagedestroy($this->im);
}
函數 randcolor($a,$b) {
$a = $a>255 ? 255:(整數)$a;
$a = $a $b = $b>255 ? 255:(整數)$b;
$b = $b for($i=0;$i $color .= str_pad(dechex(4);
}
與 $color;
}
}
/*
函數錯誤($msg,$debug = false) {
$err = new Exception($msg);
$str = "n<span>錯誤:</span>n".print_r($err->getTrace(),1)."n
";
if($debug == true) {
file_put_contents(date('Y-m-d').".log",$str);
回$str;
}否則{
死($str);
}
}
*/
?>
這是簡單的最適合的實例
🎜 >程式碼如下:
$img = new img('a.png');
$m = $img->im;
$im = $img->suolue(100);
$img->im = $m;
$img->suolue(300);
$img->merge($m,array('left'=>0,'top'=>0,'touming'=>60));
$img->merge($im,array('right'=>0,'top'=>0,'touming'=>60));
$img->merge($im,array('left'=>0,'bottom'=>0,'touming'=>60));
$img->merge($im,array('right'=>0,'bottom'=>0,'touming'=>60));
$img->write("春天來了",array('left'=>0,'top'=>0,'size'=>30,'color'=>$img ->randcolor(0,180 ),'角度'=>-45,'字體'=>'simfang.ttf','圖明'=>80));
$img->write("春天來了",array('left'=>0,'bottom'=>0,'size'=>30,'color'=>$img ->randcolor(0,180 ),'角度'=>45,'字體'=>'simfang.ttf','圖明'=>80));
$img->write("春天來了",array('right'=>0,'bottom'=>0,'size'=>30,'color'=>$img ->randcolor(0,180 ),'角度'=>-45,'字體'=>'simfang.ttf','圖明'=>80));
$img->write("春天來了",array('right'=>0,'top'=>0,'size'=>30,'color'=>$img ->randcolor(0,180 ),'角度'=>45,'字體'=>'simfang.ttf','圖明'=>80));
$img->display("gif");
以上就介紹了pimchanok leuwisetpaibul php方便水印和想要的圖形類,包括pimchanok leuwisetpaibul方面的內容,希望對PHP教程有興趣的朋友有所幫助。