手机版

php实现背景图上添加圆形标志;徽标图标的方法

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

本文实例讲述了服务器端编程语言(专业超文本预处理器的缩写)实现背景图上添加圆形标志;徽标图标的方法。分享给大家供大家参考,具体如下:

说一下步骤:

总共分3步:

1.压缩标志;徽标成固定大小的方形图片2.将标志;徽标转成圆形徽标3 .将标志;徽标与背景图合并

废话不多说,直接上代码:

?php/** *作者:friker *开发时间:20160516 * 功能:图片处理* */class ImageController扩展了CI _ Controller { public function _ _ construct(){ parent : _ _ construct();date_default_timezone_set('亚洲/上海');错误报告(E _ ALL ~ E _ NOTICE ~ E _ WARNING);$ this-load-library(' curl ');} /** * @todo :本函数用于将方形的图片压缩后* 再裁减成圆形做成徽标*与背景图合并* @返回返回url */公共函数索引(){ //头像$ headimgurl=' a.jpg//背景图$bgurl=' ./aa。png ';$ imgs[' dst ']=$ BG URL;//第一步压缩图片$ img gzip=$ this-resize _ img($ head imgurl);//第二步裁减成圆角图片$ imgs[' src ']=$ this-test($ imggzip);//第三步合并图片$ dest=$ this-merge rimg($ imgs);}公共函数resize_img($url,$path=' ./'){ $ imgname=$ path . uniqid(). jpg ';$ file=$ urllist($width,$ height)=getimagesize($ file);//获取原图尺寸$ percent=(110/$ width);//缩放尺寸$ new width=$ width * $ percent $ new height=$ height * $ percent $ src _ im=imagecreatefrom JPEG($ file);$ dst _ im=imagecreatetrue color($新宽度,$新高度);imagecopyresized($dst_im,$src_im,0,0,0,0,$newwidth,$newheight,$width,$ height);imagejpeg($dst_im,$ im gname);//输出压缩后的图片图像销毁($ dst _ im);图像销毁($ src _ im);返回$ imgname} //第一步生成圆角图片公共函数测试($url,$路径=' ./'){ $ w=110;$ h=110//原始大小$ origin _ path=$ URL $ dest _ path=$ path . uniqid(). png ';$ src=imagecreatefromstring(file _ get _ contents($ original _ path));$ new pic=imagecreatetrue color($ w,$ h);imagealphablending($newpic,false);$ transparent=imagecoloallocatelpha(新pic,0,0,0,127);$ r=$ w/2;for($ x=0;$ x $ w;$x)为($ y=0;$ y $ h;$y ){ $c=imagecolorat($src,$x,$ y);$ _ x=$ x-$ w/2;$ _ y=$ y-$ h/2;if((($ _ x * $ _ x)($ _ y * $ _ y))($ r * $ r)){ imageset pixel($ new pic,$x,$y,$ c);}else{ imagesetpixel($newpic,$x,$y,$ transparent);} } imagesavealpha($newpic,true);//标头(“内容类型:图像/png”);imagepng($newpic,$ dest _ path);图像破坏(新图片);图像销毁($ src);取消链接($ URL);返回$ dest _ path} //php合并图片公共函数mergerImg($imgs,$path=' ./') { $imgname=$path.rand(1000,9999).uniqid(). jpg ';list($max_width,$ max _ height)=getimagesize($ imgs[' dst ']);$ dests=imagecreatetrue color($ max _ width,$ max _ height);$ dst _ im=imagecreatefrompng($ imgs[' dst ']);imagecopy($dests,$dst_im,0,0,0,0,$max_width,$ max _ height);图像销毁($ dst _ im);$ src _ im=imagecreatefrompng($ imgs[' src ']);$ src _ info=getimagesize($ imgs[' src ']);imagecopy($dests,$src_im,270,202,0,0,$src_info[0],$ src _ info[1]);图像销毁($ src _ im);//var _ dump($ imgs);退出;//页眉(“内容类型:图像/JPEG”);imagejpeg($dests,$ im gname);//unlink($ imgs[' dst ']);unlink($ imgs[' src ']);返回$ imgname}}结果展示:

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

希望本文所述对大家服务器端编程语言(专业超文本预处理器的缩写)程序设计有所帮助。

版权声明:php实现背景图上添加圆形标志;徽标图标的方法是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。