php图片操作
2016-08-26 16:38
232 查看
<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; }
相关文章推荐
- 一个关于if else容易迷惑的问题
- PHP5.2.*防止Hash冲突拒绝服务攻击的Patch
- 深入理解PHP之匿名函数
- JSP/PHP基于Ajax的分页功能实现
- 关于PHP通过PDO用中文条件查询MySQL的问题。
- 什么是设计模式
- PHP数据库长连接mysql_pconnect的细节
- Php Installing An Expansion
- rem : web app适配的秘密武器
- jquery高级应用之Deferred对象
- 关于浮动与清除浮动,你应该知道的
- 数组reduce方法的高级技巧
- php7 读取php.ini[4]
- 按右键另存图片只能存BMP
- photoshop去除图片上的水印
- upload上传单张图片
- 图片引发的溢出危机(图)
- C# WinForm控件对透明图片重叠时出现图片不透明的简单解决方法