zoukankan      html  css  js  c++  java
  • PHP 打水印功能

        /**
         * @param $str  需要打水印的文字
         * @param int $size 文字大小
         * @param int $red  文字的颜色 rgb r
         * @param int $gree 文字的颜色 rgb g
         * @param int $blue 文字的颜色 rgb b
         * @param string $path 生成后图片的路径
         * @author 宁佳兵
         */
        function watermark( $str, $size=48, $red=150, $gree=150, $blue=150, $path='/Uploads/FS/photo_stamp.png' ){
            $im = imagecreatefrompng(__STATIC__.'/images/lucency.png'); //引入透明图片
            $font= __STATIC__."/fonts/msyh.ttf";//字体文件引入
            // 从 GD 手动创建水印图像
            $stamp = imagecreatetruecolor(2480, 3508);
            //设置字体背景
            imagefilledrectangle($stamp, 0, 0, 2480, 3508, 0xFFFFFF);
            $color = imagecolorallocate($stamp, $red, $gree, $blue);
            //打满全屏
            for ($i=1;$i<25;$i++){
                imagefttext($stamp, $size,50,0,150 * $i, $color, $font, $str);
    
                for ($j=1;$j<15;$j++){
                    imagefttext($stamp, $size,50,200 * $j,150 * $i, $color, $font, $str);
                }
            }
    
            // 以 50% 的透明度合并水印和图像
            imagecopymerge($im, $stamp, 0, 0, 0, 0, imagesx($stamp), imagesy($stamp), 20);
            // 将图像保存到文件,并释放内存 水印
            imagepng($im, $path);
            imagedestroy($im);
        }
    

      

  • 相关阅读:
    02:找第一个只出现一次的字符
    11-Canvas
    07-jQuery
    06-JavaScript高级
    05-Web API
    03-京东项目
    剑与远征-兑换码
    04-JavaScript基础语法
    02-CSS
    01-HTML
  • 原文地址:https://www.cnblogs.com/ningjiabing/p/11926800.html
Copyright © 2011-2022 走看看