|
@@ -15,19 +15,12 @@
|
|
|
*/
|
|
*/
|
|
|
package io.jpress.admin.controller;
|
|
package io.jpress.admin.controller;
|
|
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
-import java.math.BigInteger;
|
|
|
|
|
-import java.util.Date;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.jfinal.aop.Before;
|
|
import com.jfinal.aop.Before;
|
|
|
import com.jfinal.kit.PathKit;
|
|
import com.jfinal.kit.PathKit;
|
|
|
import com.jfinal.log.Log;
|
|
import com.jfinal.log.Log;
|
|
|
import com.jfinal.plugin.activerecord.Page;
|
|
import com.jfinal.plugin.activerecord.Page;
|
|
|
import com.jfinal.upload.UploadFile;
|
|
import com.jfinal.upload.UploadFile;
|
|
|
-
|
|
|
|
|
import io.jpress.core.JBaseCRUDController;
|
|
import io.jpress.core.JBaseCRUDController;
|
|
|
import io.jpress.core.interceptor.ActionCacheClearInterceptor;
|
|
import io.jpress.core.interceptor.ActionCacheClearInterceptor;
|
|
|
import io.jpress.model.Attachment;
|
|
import io.jpress.model.Attachment;
|
|
@@ -42,6 +35,14 @@ import io.jpress.template.Thumbnail;
|
|
|
import io.jpress.utils.AttachmentUtils;
|
|
import io.jpress.utils.AttachmentUtils;
|
|
|
import io.jpress.utils.FileUtils;
|
|
import io.jpress.utils.FileUtils;
|
|
|
import io.jpress.utils.ImageUtils;
|
|
import io.jpress.utils.ImageUtils;
|
|
|
|
|
+import io.jpress.utils.OperateImage;
|
|
|
|
|
+
|
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
|
|
+import java.io.File;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.math.BigInteger;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
@RouterMapping(url = "/admin/attachment", viewPath = "/WEB-INF/admin/attachment")
|
|
@RouterMapping(url = "/admin/attachment", viewPath = "/WEB-INF/admin/attachment")
|
|
|
@Before(ActionCacheClearInterceptor.class)
|
|
@Before(ActionCacheClearInterceptor.class)
|
|
@@ -116,6 +117,7 @@ public class _AttachmentController extends JBaseCRUDController<Attachment> {
|
|
|
String newPath = AttachmentUtils.moveFile(uploadFile);
|
|
String newPath = AttachmentUtils.moveFile(uploadFile);
|
|
|
User user = getLoginedUser();
|
|
User user = getLoginedUser();
|
|
|
|
|
|
|
|
|
|
+
|
|
|
Attachment attachment = new Attachment();
|
|
Attachment attachment = new Attachment();
|
|
|
attachment.setUserId(user.getId());
|
|
attachment.setUserId(user.getId());
|
|
|
attachment.setCreated(new Date());
|
|
attachment.setCreated(new Date());
|
|
@@ -136,6 +138,49 @@ public class _AttachmentController extends JBaseCRUDController<Attachment> {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void doUploadCutImage() {
|
|
|
|
|
+ String webRoot = PathKit.getWebRootPath();
|
|
|
|
|
+ String requestUrlMessage = this.getRequest().getScheme() +"://" + this.getRequest().getServerName() + ":" + this.getRequest().getServerPort();
|
|
|
|
|
+ Attachment attachment = AttachmentQuery.me().findById(getParaToBigInteger("sourceId"));
|
|
|
|
|
+ int x1 = getParaToInt("x1");
|
|
|
|
|
+ int x2 = getParaToInt("x2");
|
|
|
|
|
+ int y1 = getParaToInt("y1");
|
|
|
|
|
+ int y2 = getParaToInt("y2");
|
|
|
|
|
+ int width = x2 - x1;
|
|
|
|
|
+ int height = y2 - y1;
|
|
|
|
|
+ String srcpath = requestUrlMessage + "/jpress" + attachment.getPath();
|
|
|
|
|
+ String type = attachment.getSuffix().substring(1);
|
|
|
|
|
+ //新截取的图片名称在原图名称上加上时间戳
|
|
|
|
|
+ long time = System.currentTimeMillis();
|
|
|
|
|
+ String title = attachment.getTitle().split("\\.")[0] + time + attachment.getSuffix();
|
|
|
|
|
+ String subpath = requestUrlMessage + "/jpress" + "/attachment/" + time + attachment.getSuffix();
|
|
|
|
|
+ /*srcpath.replaceAll("/","-");*/
|
|
|
|
|
+ BufferedImage bufferedImage = OperateImage.getIconInfo(srcpath);
|
|
|
|
|
+ OperateImage o = new OperateImage(x1, y1, width, height);
|
|
|
|
|
+ //o.setSrcpath(srcpath);
|
|
|
|
|
+ o.setSourceImg(bufferedImage);
|
|
|
|
|
+ o.setSubpath("D:\\pictest\\" + time + attachment.getSuffix() );
|
|
|
|
|
+ try {
|
|
|
|
|
+ File cutImage = o.cut(type);
|
|
|
|
|
+ /*Attachment cutImage = new Attachment();
|
|
|
|
|
+ attachment.setUserId(attachment.getUserId());
|
|
|
|
|
+ attachment.setCreated(new Date());
|
|
|
|
|
+ attachment.setTitle(title);
|
|
|
|
|
+ attachment.setPath("/attachment/" + time + attachment.getSuffix());
|
|
|
|
|
+ attachment.setSuffix(attachment.getSuffix());
|
|
|
|
|
+ attachment.setMimeType(attachment.getMimeType());
|
|
|
|
|
+ cutImage.save();*/
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
|
+ json.put("success", true);
|
|
|
|
|
+ json.put("src", getRequest().getContextPath() + attachment.getPath());
|
|
|
|
|
+ renderJson(json.toString());
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ renderJson("success", false);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void processImage(String newPath) {
|
|
private void processImage(String newPath) {
|
|
|
if (!AttachmentUtils.isImage(newPath))
|
|
if (!AttachmentUtils.isImage(newPath))
|
|
|
return;
|
|
return;
|