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