Exemple #1
0
function addWater($imageFile, $saveFile = '')
{
    if (!file_exists($imageFile)) {
        return;
    }
    if (!yd_is_image($imageFile)) {
        return;
    }
    $data = YdCache::readWater();
    $WaterEnable = $data['WATER_ENABLE'];
    if ($WaterEnable == 1) {
        import('ORG.Util.Image.ThinkImage');
        $img = new ThinkImage(THINKIMAGE_GD, $imageFile);
        $position = $data['WATER_POSITION'];
        $saveFile = empty($saveFile) ? $imageFile : $saveFile;
        if ($data['WATER_TYPE'] == 2) {
            //文字水印
            $text = $data['WATER_TEXT'];
            $font = './Public/font/' . $data['WATER_FONT'];
            if (!is_file($font)) {
                return;
            }
            //水印字体不存在则直接返回
            $size = $data['WATER_TEXT_SIZE'];
            $color = $data['WATER_TEXT_COLOR'];
            $angle = $data['WATER_TEXT_ANGLE'];
            $offset = array($data['WATER_OFFSET_X'], $data['WATER_OFFSET_Y']);
            $img->text($text, $font, $size, $color, $position, $offset, $angle)->save($saveFile);
        } else {
            if ($data['WATER_TYPE'] == 1) {
                //图片水印
                /*
                $pic = $_SERVER['DOCUMENT_ROOT'].$data['WATER_PIC'];
                if ( !file_exists($pic) ){
                	return;
                }
                $right = $data['WATER_RIGHT'];
                $bottom = $data['WATER_BOTTOM'];
                $trans = $data['WATER_TRANS'];
                import("ORG.Util.Image");
                Image::water($imageFile, $pic, null, $trans, $right, $bottom);
                */
                $pic = $_SERVER['DOCUMENT_ROOT'] . $data['WATER_PIC'];
                if (!file_exists($pic)) {
                    return;
                }
                $img->water($pic, $position)->save($saveFile);
            }
        }
    }
}
Exemple #2
0
function addWater($imageFile, $saveFile = '')
{
    if (!file_exists($imageFile)) {
        return;
    }
    if (!yd_is_image($imageFile)) {
        return;
    }
    $data = YdCache::readWater();
    $WaterEnable = $data['WATER_ENABLE'];
    if ($WaterEnable == 1) {
        import('ORG.Util.Image.ThinkImage');
        $img = new ThinkImage(THINKIMAGE_GD, $imageFile);
        $position = $data['WATER_POSITION'];
        $saveFile = empty($saveFile) ? $imageFile : $saveFile;
        if ($data['WATER_TYPE'] == 2) {
            $text = $data['WATER_TEXT'];
            $font = './Public/font/' . $data['WATER_FONT'];
            if (!is_file($font)) {
                return;
            }
            $size = $data['WATER_TEXT_SIZE'];
            $color = $data['WATER_TEXT_COLOR'];
            $angle = $data['WATER_TEXT_ANGLE'];
            $offset = array($data['WATER_OFFSET_X'], $data['WATER_OFFSET_Y']);
            $img->text($text, $font, $size, $color, $position, $offset, $angle)->save($saveFile);
        } else {
            if ($data['WATER_TYPE'] == 1) {
                $pic = $_SERVER['DOCUMENT_ROOT'] . $data['WATER_PIC'];
                if (!file_exists($pic)) {
                    return;
                }
                $img->water($pic, $position)->save($saveFile);
            }
        }
    }
}