php生成图片及文字水印
首页->学习资料->编程语言->php教程->php技巧 关键词: 发布时间:2018-08-01 09:43:16 浏览次数:921

场景:网站统计代码,在用户网站是,根据一个字段值,显示图片或文字水印图片icon


public function createIcon($icon)
{
    //图标类型 0:不显示 1:默认 2:默认(篮色) 3:默认(绿) 4:默认(紫) 10:文字显示

    $config = config('img');

    $width = $config['width'];
    $widthTxt = $config['width_txt'];
    $height = $config['height'];

    $bgRed = $config['bg_red'];
    $bgGreen = $config['bg_green'];
    $bgBlue = $config['bg_blue'];

    $textRed = $config['text_red'];
    $textGreen = $config['text_green'];
    $textBlue = $config['text_blue'];
    $ds = DIRECTORY_SEPARATOR;
    $rootDir = $_SERVER['DOCUMENT_ROOT'];

    //图片或文字时,显示的宽度不一样
    $hbWidth = $icon == 10 ? $widthTxt : $width;

    //画布
    if (function_exists('imagecreatetruecolor')) {
        $hb = imagecreatetruecolor($hbWidth, $height);
    } else {
        $hb = imagecreate($hbWidth, $height);
    }

    if ($icon > 0 && $icon <= 4) {
        //显示icon图片
        $img = $rootDir . $ds . 'source' . $ds . 'img' . $ds . $this->img[$icon];
        $source = imagecreatefrompng($img);
        imagecopyresampled($hb, $source, 0, 0, 0, 0, $width, $height, $width, $height);
        imagepng($hb);
        imagedestroy($source);
    } else if ($icon == 10) {
        //显示文字icon
        //图片背景
        $background = imagecolorallocate($hb, $bgRed, $bgGreen, $bgBlue);
        //填充背景
        imagefill($hb, 0, 0, $background);
        //字体颜色
        $black = imagecolorallocate($hb, $textRed, $textGreen, $textBlue);
        //字体文件
        $font = $rootDir . $ds . 'source' . $ds . 'font' . $ds . 'simsun.ttc';
        //显示的文字
        $defaultTxt = $config['default_txt'];
        //将文本写入图像:4个数字依次为:字号,旋转角度,padding-left,padding-top
        imagefttext($hb, 10, 0, 0, 16, $black, $font, $defaultTxt);
        imagepng($hb);
    }
    imagedestroy($hb);
}


赞:(0)
踩:(0)
相关文章
phpexcel设置行高及列宽,背景颜色,
单点登录sso原理及php实现方式及de
在php中用curl请求java接口无法获
免费ip地址查询接口
php,java,android, aes加解密-加密
地图上计算两点间的距离
关于百度地图的一些技巧
php中empty,is_null,isset的区别
windows及linux下composer安装教程
一种精妙的数据查询与存储方式
热门文章
win7中将文件拷贝到虚拟机linux下
phpexcel设置行高及列宽,背景颜色,
rabbitmq无法启动
intellij idea不显示git push按钮
php7中使用mongodb的aggregate进行
centos7.4 64位下swoole安装及配置
laravel页面静态化的方法
navicate连接mycat报1184错误
单点登录sso原理及php实现方式及de
devops-jenkins容器为pending状态
好评文章
phpexcel设置行高及列宽,背景颜色,
php7中使用mongodb的aggregate进行
intellij idea打开文件所在文件夹
windows下使用MongoDB Compass Com
win7中将文件拷贝到虚拟机linux下
laravel 中悲观锁 & 乐观锁的使用
单点登录sso原理及php实现方式及de
navicate连接mycat报1184错误
rabbitmq无法启动
laravel整合dingo/api方法步骤:jwt
标签
rabbitmq mysql备份 elasticsearch golang swoole
我的项目
【github】www.github.com/hurong241
【码云】gitee.com/hu_rong/projects
【docker hub】hub.docker.com/repositories/hurong241
【packagist】packagist.org/users/hurong241/packages
站点信息
建站时间:2011年
文章数:610篇
浏览数:953068
粤ICP备18028092号-1  微信:hurong241