zoukankan      html  css  js  c++  java
  • thinkphp在为图片添加png水印不足的处理

    thinkphp在为图片加水印的时候。如果水印图片是png图片,透明度处理很不理想,与是做以下处理

    在Image.class.php中新增

    static function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct){
            $opacity=$pct;
            // getting the watermark width
            $w = imagesx($src_im);
            // getting the watermark height
            $h = imagesy($src_im);
                   
            // creating a cut resource
            $cut = imagecreatetruecolor($src_w, $src_h);
            // copying that section of the background to the cut
            imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);
            // inverting the opacity
            //$opacity = 100 - $opacity;
                   
            // placing the watermark now
            imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);
            imagecopymerge($dst_im, $cut, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $opacity);
        }

    然后在water方法中把原来的替换就ok,替换方法如下:

    //生成混合图像(原来系统中的,注释掉)

    //imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo['width'], $wInfo['height'], $alpha);
    //新加===================================================================
    self::imagecopymerge_alpha($sImage, $wImage, $posX, $posY, 0, 0, $wInfo['width'], $wInfo['height'], $alpha);
  • 相关阅读:
    Wannafly挑战赛9
    acm之图论基础
    Codeforces Round #459 (Div. 2)
    Codeforces Round #460 (Div. 2)
    浙南联合训练赛20180129
    AtCoder Regular Contest 090
    牛客练习赛11
    2018年1月26日天梯赛练习1
    csa Round #66 (Div. 2 only)
    EOJ Monthly 2018.1
  • 原文地址:https://www.cnblogs.com/blueskycc/p/5509367.html
Copyright © 2011-2022 走看看