设置缩略图边框
分类:热门新闻

?

复制代码 代码如下:

function setMaskTxtPct($n) { $this-mask_txt_pct = (int)$n; } /** * 设置缩略图边框 * * @param (类型) (参数名) (描述) */ function setDstImgBorder($size=1, $color=#000000) { $this-img_border_size = (int)$size; $this-img_border_color = $color; } /** * 水平翻转 */ function flipH() { $this-_flip_x++; } /** * 垂直翻转 */ function flipV() { $this-_flip_y++; } /** * 设置剪切类型 * * @param (类型) (参数名) (描述) */ function setCutType($type) { $this-cut_type = (int)$type; } /** * 设置图片剪切 * * @param integer $width 矩形剪切 */ function setRectangleCut($width, $height) { $this-fill_w = (int)$width; $this-fill_h = (int)$height; } /** * 设置源图剪切起始坐标点 * * @param (类型) (参数名) (描述) */ function setSrcCutPosition($x, $y) { $this-src_x = (int)$x; $this-src_y = (int)$y; } /** * 创建图片,主函数 * @param integer $a 当缺少第二个参数时,此参数将用作百分比, * 否则作为宽度值 * @param integer $b 图片缩放后的高度 */ function createImg($a, $b=null) { $num = func_num_args(); if(1 == $num) { $r = (int)$a; if($r 1) { die(图片缩放比例不得小于1); } $this-img_scale = $r; $this-_setNewImgSize($r); } if(2 == $num) { $w = (int)$a; $h = (int)$b; if(0 == $w) { die(目标宽度不能为0); } if(0 == $h) { die(目标高度不能为0); } $this-_setNewImgSize($w, $h); } if($this-_flip_x%2!=0) { $this-_flipH($this-h_src); } if($this-_flip_y%2!=0) { $this-_flipV($this-h_src); } $this-_createMask(); $this-_output(); // 释放 if(imagedestroy($this-h_src) imagedestroy($this-h_dst)) { Return true; } else { Return false; } }?

im = call_user_func_array,$args); } function __call { if(function_exists { $funcstr = 'image'.$func; }elseif (function_exists{ $funcstr = $func; }else { error; } return call_user_func_array; } /* *创建图像 *@param string/int 图片文件路径或者宽度 *@param int 高度,可省略 *@param string 6位16进制整数 */ function create { $args = func_get_args(); if { $this->file = $args[0]; $size = getimagesize or error; $this->size = $this->size ? $this->size : $size; $type = image_type_to_extension; $this->type = $this->type ? $this->type : $type; $createfunc = 'imagecreatefrom'.$type; $im = $createfunc; }elseif$args[0]>0 and { $im = imagecreatetruecolor$args[1]) or error; if { $color = hexdec; imagecolortransparent; }else { $color = hexdec(str_replace; } $this->size = $this->size ? $this->size : array$args[1]); imagefill; }else { error; } //imagealphablending;//这两行用来记录透明通道 imagesavealpha; imageinterlace;//开启隔行扫描 return $im; } /* *生成缩略图 *@param int $w 新图片的宽度 *@param int $h 新图片的宽度 *@param string/bool $color 可选,新图片的背景色,false或空为透明 *@param bool $lashen 可选,是否拉伸,默认不拉伸 */ function suolue($w = null,$h = null,$color = false,$lashen = false) { $w_o = imagesx; $h_o = imagesy; if($w == null and $h != null) { $w = $h *威尼斯登录首页, $w_o/$h_o; }elseif ($w != null and $h == null){ $h = $w * $h_o/$w_o; } $this->size = null; $im = $this->create; $w_n = $w; $h_n = $h; if { $h_n = $w*$h_o/$w_o; $y = /2; }elseif { $w_n = $h*$w_o/$h_o; $x = /2; } if { $w_n = $w; $h_n = $h; $x = 0; $y = 0; } imagecopyresampled($im,$this->im,$x,$y,0,0,$w_n,$h_n,$w_o,$h_o); //imagedestroy; $this->im = $im; return $im; } /* *在图片上写字 *@param string $str 要写的字符串 *@param array $arg 字符串相关的参数,为一个关联数组,left 为距左边距离,right为距右边距离,left优先,top为距顶部距离,bottom为距底部距离,top优先;angle为角度,color为6位数16进制颜色,touming为文字透明度,font为字体文件 */ function write($str = '' , $arg = array { $size = $arg['size'] ? $arg['size'] : 20; $angle = $arg['angle'] ? $arg['angle'] : 0 ; $color = $arg['color'] ? $arg['color'] : '000000'; $touming = $arg['touming'] ? $arg['touming'] : 100; $touming = dechex*127/100); $color = hexdec($touming.str_replace; $font = $arg['font'] ? $arg['font'] : 'arial.ttf'; $boxarr = imagettfbbox($size,$angle,$font,$str); $w = imagesx; $h = imagesy; $x_l = $x_r = $boxarr[0]; $y_t = $y_b = $boxarr[1]; for { $x_l = $boxarr[$i] < $x_l ? $boxarr[$i] : $x_l; $x_r = $boxarr[$i] > $x_r ? $boxarr[$i] : $x_r; $y_t = $boxarr[$i+1] < $y_t ? $boxarr[$i+1] : $y_t; $y_b = $boxarr[$i+1] > $y_b ? $boxarr[$i+1] : $y_b; } $width = $x_r - $x_l; $height = $y_b - $y_t; /*获取精确偏移量*/ $im = $this->create; $tm = hexdec; imagettftext($im,$size,$angle,$width*2,$height*2,$color,$font,$str); for($i=0;$i0;$i--) { for($ii=$y_t;$ii0;$i--) { for($ii=$x_l;$ii<=$x_r;$ii++) { if(imagecolorat { $y_b = $i; break; } } } $x_off = $x_l - $width*2; $y_off = $y_b - $height*2; $width = $x_r - $x_l; //精确宽度 $height = $y_b - $y_t; //精确高度 imagedestroy; if { $x = $arg['left'] - $x_off; }elseif { $x = $w - $arg['right'] - $width - $x_off; }else { $x = /2 - $x_off; } if { $y = $arg['top'] - $y_off + $height; }elseif ){ $y = $h - $arg['bottom'] - $y_off; }else { $y = /2 - $y_off; } imagettftext($this->im,$size,$angle,$x,$y,$color,$font,$str); return $this->im; } /* *合并图片 *@param string/resource $file 图片文件路径或这图片标识符 *@param array $arg 字符串相关的参数,为一个关联数组,left 为距左边距离,right为距右边距离,left优先,top为距顶部距离,bottom为距底部距离,top优先;touming为文字透明度 */ function merge { if { $imc = $this->create; }elseif=='resource') { $imc = $file; }else { error; } $touming = $arg['touming'] ? $arg['touming'] : 100 ; $w = imagesx; $h = imagesy; $width = imagesx; $height = imagesy; if { $x = $arg['left']; }elseif { $x = $w - $arg['right'] - $width; }else { $x = /2; } if { $y = $arg['top']; }elseif ){ $y = $h - $height - $arg['bottom']; }else { $y = /2; } imagecopymergegray($this->im,$imc,$x,$y,0,0,$width,$height,$touming); } /* *输出图片 *@param string $type *@param string $filename 要转存的文件路径 *@param int $zhiliang jpeg图片特有的,图像清晰度 */ function display($type = null,$filename = null,$zhiliang = null) { if { $type = $this->type ? $this->type : 'jpg'; } if(($type == 'jpeg' or $type == 'jpg') and $zhiliang == null) { $type = 'jpeg'; $zhiliang = 100; } if { header('Content-type: image/'.$type); } $displayfunc = 'image'.$type; $displayfunc($this->im,$filename,$zhiliang); imagedestroy; } function randcolor { $a = $a>255 ? 255 : $a; $a = $a<0 ? 0 : $a; $b = $b>255 ? 255 : $b; $b = $b<0 ? 0 : $b; for { $color .= str_pad), 2, "0", STR_PAD_LEFT); } return $color; } } /* function error { $err = new Exception; $str = "

n错误:n".print_r."n

"; if { file_put_contents.".log",$str); return $str; }else{ die; } } */ ?>这是简单的用法实例 复制代码 代码如下:$img = new img; $m = $img->im; $im = $img->suolue; $img->im = $m; $img->suolue; $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,'angle'=>-45,'font'=>'simfang.ttf','touming'=>80)); $img->write("春天来了",array('left'=>0,'bottom'=>0,'size'=>30,'color'=>$img->randcolor,'angle'=>45,'font'=>'simfang.ttf','touming'=>80)); $img->write("春天来了",array('right'=>0,'bottom'=>0,'size'=>30,'color'=>$img->randcolor,'angle'=>-45,'font'=>'simfang.ttf','touming'=>80)); $img->write("春天来了",array('right'=>0,'top'=>0,'size'=>30,'color'=>$img->randcolor,'angle'=>45,'font'=>'simfang.ttf','touming'=>80)); $img->display;

本文由威尼斯在线注册平台发布于热门新闻,转载请注明出处:设置缩略图边框

上一篇:  PHP中提供了一多元的I/O函数,作者改成了''/'' 下一篇:威尼斯登录首页view层的接口将数据按一定的方式传给模板解析类,使用渲染render
猜你喜欢
热门排行
精彩图文