博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php图像处理函数大全(缩放、剪裁、缩放、翻转、旋转、透明、锐化的实例总结)
阅读量:4198 次
发布时间:2019-05-26

本文共 1515 字,大约阅读时间需要 5 分钟。

php图片处理代码分享,包括缩放、剪裁、缩放、翻转、旋转、透明、锐化等。

一、创建图片资源

imagecreatetruecolor(width,height);
imagecreatefromgif(图片名称);
imagecreatefrompng(图片名称);
imagecreatefromjpeg(图片名称);画出各种图像 imagegif(图片资源,保存路径);
imagepng()
imagejpeg();
二、获取图片属性
imagesx(res//宽度
imagesy(res//高度
getimagesize(文件路径)
返回一个具有四个单元的数组。索引 0 包含图像宽度的像素值,索引 1 包含图像高度的像素值。索引 2 是图像类型的标记:1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC,10 = JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM。这些标记与 PHP 4.3.0 新加的 IMAGETYPE 常量对应。索引 3 是文本字符串,内容为“height="yyy" width="xxx"”,可直接用于 IMG 标记。
销毁图像资源
imagedestroy(图片资源);
三、透明处理
PNG、jpeg透明色都正常,只有gif不正常
imagecolortransparent(resource image [,int color])//将某个颜色设置成透明色
imagecolorstotal()
imagecolorforindex();
四、图片的裁剪
imagecopyresized()
imagecopyresampled();
五、加水印(文字、图片)
字符串编码转换string iconv ( string $in_charset , string $out_charset , string $str )
六、图片旋转
imagerotate();//制定角度的图片翻转
七、图片的翻转
沿X轴 沿Y轴翻转
八、锐化
imagecolorsforindex()
imagecolorat()
在图片上画图形 $img=imagecreatefromgif("./images/map.gif");

=0 && $otst < imagecolorstotal($img)){//判断索引色$tran=imagecolorsforindex($img, $otsc);//索引颜色值$newt=imagecolorallocate($new, $tran["red"], $tran["green"], $tran["blue"]);imagefill($new, 0, 0, $newt);imagecolortransparent($new, $newt);}imagecopyresized($new, $img, 0, 0, 0, 0, $width, $height, $s_w, $s_h);imagegif($new, $newfile);imagedestroy($new);imagedestroy($img);}thumn("images/map.gif", 200, 200, "./images/map3.gif");
图片裁剪

图片加水印 文字水印

图片旋转
图片水平翻转垂直翻转

转载地址:http://nbdli.baihongyu.com/

你可能感兴趣的文章
【ReactNative】真机上无法调试 could not connect to development server
查看>>
【XCode 4.6】常用快捷键 特别是格式化代码ctrl+i
查看>>
【iOS游戏开发】icon那点事 之 实际应用(二)
查看>>
【iOS游戏开发】icon那点事 之 图标设计(三)
查看>>
【IOS游戏开发】之测试发布(Distribution)
查看>>
【IOS游戏开发】之IPA破解原理
查看>>
【一天一道LeetCode】#45. Jump Game II
查看>>
【一天一道LeetCode】#46. Permutations
查看>>
【一天一道LeetCode】#47. Permutations II
查看>>
【一天一道LeetCode】#48. Rotate Image
查看>>
【一天一道LeetCode】#56. Merge Intervals
查看>>
【一天一道LeetCode】#57. Insert Interval
查看>>
【一天一道LeetCode】#58. Length of Last Word
查看>>
【一天一道LeetCode】#59. Spiral Matrix II
查看>>
【一天一道LeetCode】#30. Substring with Concatenation of All Words
查看>>
【一天一道LeetCode】#60. Permutation Sequence.
查看>>
【一天一道LeetCode】#62. Unique Paths
查看>>
【一天一道LeetCode】#61. Rotate List
查看>>
【一天一道LeetCode】#63. Unique Paths II
查看>>
【一天一道LeetCode】#36. Valid Sudoku
查看>>