手机版

PHP实现图片反色处理功能[测试可用]

时间:2021-09-01 来源:互联网 编辑:宝哥软件园 浏览:

本文给出了一个例子来说明PHP如何反转图片的颜色。分享给大家参考,如下:

今天,有必要使用php来反转颜色和灰色的图片。之前不知道可行不可行,后来看到imagefilter()函数,足以变成灰色,好强大;

Imagefilter ($ im,img _ filter _ grade)当然,也有人在css中设置灰度

style type=' text/CSS ' img {-web kit-filter :灰度(1);/* Webkit */filter : gray;/* IE6-9 */filter:灰度(1);/* W3C */}/stylephp颜色代码:

?Php/***主要用于图像处理函数*///函数color($url) {//获取图片的信息List ($ width,$ height,$ type,$ attr)=GetImageSize($ URL);$ imagetype=strtolow(image _ type _ to _ extension($ type,false));$fun='imagecreatefrom '。($imagetype=='jpg '?JPEG ' : $ imagetype);$ img=$ fun($ URL);for($ y=0;$ y $高度;$ y){ for($ x=0;$ x $宽度;$x) {//获取color $index=imagecolorat($img,$x,$y)的所有值;//获取colors $ color=imagecolorsforindex($ img,$ index)的数组;//颜色值反转$ red=256-$ color[' red '];$ green=256-$ color[' green '];$ blue=256-$ color[' blue '];$hex=imagecolorallocate($img,$red,$green,$ blue);//为每个像素分配一个颜色值imagesetpixel($img,$x,$y,$ hex);} }//输出图片开关($ imagetype){ case ' gif ' : imagegif($ img);打破;case ' JPEG ' : image JPEG($ img);打破;case ' png ' : image png($ img);打破;default: break}}测试代码:

$ imgurl=' 1.jpg回声颜色($ imgurl);原图(以这张边肖常用的毁童年恶搞图为例):

运行后(这里主要是基于测试。至于颠覆三观或五官的画面,边肖就不多问了~):

更多对PHP相关内容感兴趣的读者可以查看本网站专题:《PHP图形与图片操作技巧汇总》、《php文件操作总结》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《PHP运算与运算符用法总结》、《php面向对象程序设计入门教程》、《PHP网络编程技巧总结》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》、《php常见数据库操作技巧汇总》。

希望本文对PHP编程有所帮助。

版权声明:PHP实现图片反色处理功能[测试可用]是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。