Modify the Ueditor1_4_3 editor JSP version to allow uploading images to support watermarks

Source: Internet
Author: User

Main ideas: Ueditor editor upload images to request requests sent to the background, the background receive through the form of stream processing, we just in the background to intercept the image file and watermark processing can be implemented.

First, download the Ueditor1_4_3 editor JSP version, so that it can work properly;

Second, modify the source code

Main modified Storagemanager.java file

1) Add the code that will upload the file and watermark file to synthesize the watermark picture

 /** * will upload files and watermark file composite watermark Picture */public static void Setwatermark (file targetfile, string RootPath, string path) thro        WS IOException {//source file 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);                Watermark file String FILENAME = RootPath + "Ueditor/image/watermark.png"; When FILENAME is a URL address, such as: http://www.baidu.com/abc.png//URL url = new URL (FILENAME),//inputstream pressis = URL.                OpenStream ();        When FILENAME is a local path, such as: 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) Modify the Savetmpfile method

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); }//Determine if the picture file if (maxSize = = 2048000) {try {//Ga Shuiyin 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;}

Third, restart the upload image directly with a watermark.

Modify the Ueditor1_4_3 editor JSP version to allow uploading images to support watermarks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.