php图片操作

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">源于猪八戒网上的一次招标,前前后后,学到了不少东西。自己简单整理下。</span>

在图片上写文字 

function Xiezi($tt,$width,$height){
		$image = ImageCreateFromJPEG( "test.jpg" );
		$cor = imagecolorallocate($image, 0, 0, 0);
		$font = 'xihei.ttf';
		//$tt = '我们的灵魂';
		//imagepsslantfont($font, 22.5);
		$a = im($image, 12, 0, $width, $height, $cor, $font, $tt,3);
		//header('Content-type: image/jpeg');
		imagejpeg($image,"test.jpg");
	}
	function im(&$image, $size, $angle, $start_x, $y, $color, $font, $text,$spancing) {
		 
		for ($i=0;$i<mb_strlen($text,'utf8');$i++) {
		    $t = mb_substr($text, $i,1,'utf8');
		    $x = $i*($size+$spancing);
		    imagettftext($image, $size, $angle, $x+$start_x, $y, $color, $font, $t);
		    }  
		 
		}

图片的缩放操作

//图片缩放
	function thumb($filename,$width=200,$height=200){
		list($width_org,$height_org)=getimagesize($filename);
		/*if($width && ($width_org < $height_org)){
			$width=($height/$height_org)*$width_org;
		}
		else{
			$height=($width/$width_org)*$height_org;
		}*/
		//如果上面代码没被注释 那么是等比例缩放
		$image_p=imagecreatetruecolor($width, $height);
		$image=imagecreatefromjpeg($filename);
		imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_org, $height_org);
		imagejpeg($image_p,$filename,100);

		imagedestroy($image_p);
		imagedestroy($image);
	}

加水印函数

//加水印的函数
	function watermark($filename,$water){
		list($b_w,$b_h)=getimagesize($filename);
		list($w_w,$w_h)=getimagesize($water);
		$posX=rand(0,($b_w-$w_w));
		$posY=rand(0,($b_h-$b_h));
		$back=imagecreatefromjpeg($filename);
		$water=imagecreatefromjpeg($water);
		imagecopy($back, $water, 519, 111, 0, 0, $w_w, $w_h);
		imagejpeg($back,"test.jpg");
		imagedestroy($back);
		imagedestroy($water);
	}

生成随机字符串

	//生成随机字符串
	function getRandChar($length){
	   $str = null;
	   $strPol = "0123456789";
	   $max = strlen($strPol)-1;

	   for($i=0;$i<$length;$i++){
	    $str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
	   }

	   return $str;
	}

字符串逐字拆分函数

function arr_split_zh($tempaddtext){
	   	$tempaddtext = iconv("UTF-8", "gb2312", $tempaddtext);
	    $cind = 0;
	    $arr_cont=array();
	    for($i=0;$i<strlen($tempaddtext);$i++)
	    {
	        if(strlen(substr($tempaddtext,$cind,1)) > 0){
	        	if(ord(substr($tempaddtext,$cind,1)) < 0xA1 ){ //如果为英文则取1个字节
	                array_push($arr_cont,substr($tempaddtext,$cind,1));
	                $cind++;
	            }else{
	                array_push($arr_cont,substr($tempaddtext,$cind,2));
	                $cind+=2;
	            }
	        }
	    }
	   foreach ($arr_cont as &$row)
	   {
	   		$row=iconv("gb2312","UTF-8",$row);
	   }
		return $arr_cont;
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值