国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JSP > 正文

修改ueditor1_4_3編輯器jsp版使上傳圖片支持水印

2019-11-14 15:05:42
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

主要思路:ueditor編輯器上傳圖片以request請(qǐng)求發(fā)送到后臺(tái),后臺(tái)接收通過(guò)流的形式進(jìn)行處理,我們只要在后臺(tái)攔截到圖片文件并進(jìn)行加水印處理就能夠?qū)崿F(xiàn)該功能。

一、 下載ueditor1_4_3編輯器jsp版,使其能夠正常工作;

二、 修改源碼

  主要修改StorageManager.java文件

      image

  1) 添加將上傳文件和水印文件合成帶水印圖片的代碼

 /**     * 將上傳文件和水印文件合成帶水印圖片     */    public static void setWaterMark(File targetFile, String rootPath, String path) throws IOException {        //源文件        Image src = ImageIO.read(targetFile);        int width = src.getWidth(null);        int height = src.getHeight(null);        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);        Graphics g = image.createGraphics();        g.drawImage(src, 0, 0, width, height, null);        // 水印文件        String FILENAME = rootPath + “ueditor/image/waterMark.png”;                //FILENAME為url地址時(shí),如:http://www.baidu.com/abc.png//        URL url = new URL(FILENAME);//        InputStream PRessIs = url.openStream();                //FILENAME為本地路徑時(shí),如:D:/abc.png        InputStream pressIs = new FileInputStream(FILENAME);        Image src_biao = ImageIO.read(pressIs);        int width_biao = src_biao.getWidth(null);        int height_biao = src_biao.getHeight(null);        g.drawImage(src_biao, width - width_biao, height - height_biao, width_biao, height_biao, null);        g.dispose();        FileOutputStream out = new FileOutputStream(path);        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);        encoder.encode(image);        out.close();    }

  2) 修改saveTmpFile方法

private static State saveTmpFile(File tmpFile, String rootPath, String path, Long maxSize) {    State state = null;    File targetFile = new File(path);    if (targetFile.canWrite()) {        return new BaseState(false, AppInfo.PERMISSION_DENIED);    }    try {        FileUtils.moveFile(tmpFile, targetFile);    } catch (IOException e) {        return new BaseState(false, AppInfo.IO_ERROR);    }    //判斷是否為圖片文件    if (maxSize == 2048000) {        try {            //加水印            setWaterMark(targetFile, rootPath, path);        } catch (IOException e) {            e.printStackTrace();        }    }    state = new BaseState(true);    state.putInfo("size", targetFile.length());    state.putInfo("title", targetFile.getName());    return state;}

三、 重啟上傳圖片后直接帶水印。


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 突泉县| 衡东县| 墨江| 福安市| 山西省| 宁陵县| 太和县| 大安市| 上思县| 南平市| 唐山市| 新安县| 合江县| 保定市| 阳江市| 兴义市| 库尔勒市| 密云县| 邢台市| 绥滨县| 乌鲁木齐市| 新安县| 融水| 长葛市| 木里| 海阳市| 浪卡子县| 安福县| 江安县| 津南区| 永清县| 商南县| 黎城县| 德令哈市| 宽城| 正蓝旗| 磐石市| 色达县| 嫩江县| 甘南县| 武平县|