中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

PHP根據(jù)圖片色界在不同位置加水印

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用

PHP根據(jù)圖片色界在不同位置加水印

    function add_wm($nmw_water, $src_file, $output_file, $x, $y) {      
        if(file_exists($output_file))      
            return;      
                         
        $w1 = MagickGetImageWidth($nmw_water);      
        $h1 = MagickGetImageHeight($nmw_water);      
                         
        $nmw =NewMagickWand();      
        MagickReadImage($nmw, $src_file);      
                         
        // 默認(rèn)的加水印位置調(diào)整      
        $lt_w = 50;      
        $lt_h = 50;      
                         
        if($x == 0){      
            $w = MagickGetImageWidth($nmw);      
            $h = MagickGetImageHeight($nmw);      
                         
            $x = $w;      
            $y = $h;      
        }else{      
            // 根據(jù)具體情況調(diào)整      
            $lt_w = 30;      
            $lt_h = 40;      
        }      
                         
        MagickCompositeImage($nmw, $nmw_water, MW_OverCompositeOp, $x - $w1 - $lt_w, $y - $h1 - $lt_h);      
        MagickWriteImage($nmw, $output_file);      
                         
        DestroyMagickWand($nmw);              
    }      
                         
    // 還是groovy的eachFileRecurse好用啊      
    function add_wm_recurse($nmw_water, $to_dir, $output_dir, $arr) {      
        $dp = dir($to_dir);      
        while($file=$dp->read()){      
            if($file != '.' && $file != '..'){      
                     
                     
                if(is_dir($to_dir . '/' . $file)){      
                    mkdir($output_dir . '/' . $file);      
                    add_wm_recurse($nmw_water, $to_dir . '/' . $file, $output_dir . '/' . $file, $arr);      
                }else{      
                    if(!array_key_exists($to_dir . '/' . $file, $arr)){      
                        continue;      
                     
                    }      
                         
                    $sub_arr = $arr[$to_dir . '/' . $file];      
                    if($sub_arr){      
                        $x = intval($sub_arr[0]);      
                        $y = intval($sub_arr[1]);      
                        add_wm($nmw_water, $to_dir . '/' . $file, $output_dir . '/' . $file, $x, $y);      
                    }      
                }      
            }      
        }      
        $dp->close();      
    }      
                         
    $to_dir = './resized';      
    $output_dir = './output';      
                         
    // 這個(gè)是我用java的ImageIO遍歷圖片像素獲取的符合褲子顏色的區(qū)域的坐標(biāo)array(posX, posY)      
    $arr = array(      
        array(50, 50)      
    );      
                         
    $water = './water.png';      
    $nmw_water =NewMagickWand();      
    MagickReadImage($nmw_water, $water);      
                         
    add_wm_recurse($nmw_water, $to_dir, $output_dir, $arr);      
                         
    DestroyMagickWand($nmw_water);

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:Android獲取手機(jī)號碼及運(yùn)營商

下一篇:Java 下載支持?jǐn)帱c(diǎn)續(xù)傳服務(wù)端