| @@ -15,6 +15,7 @@ import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.MallResource; | |||
| import com.iformall.service.MallResourceService; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.ImgUtil; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.slf4j.Logger; | |||
| @@ -26,9 +27,6 @@ import org.springframework.web.bind.annotation.RequestParam; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import javax.imageio.ImageIO; | |||
| import java.awt.*; | |||
| import java.awt.image.BufferedImage; | |||
| import java.io.*; | |||
| import java.net.URL; | |||
| import java.util.*; | |||
| @@ -146,24 +144,7 @@ public class UploadController extends BaseController { | |||
| return data; | |||
| } | |||
| /** | |||
| * 图片瘦身 | |||
| * @param input | |||
| * @param newFile | |||
| * @throws Exception | |||
| */ | |||
| private static File thinImage(String input,String newFile) throws IOException { | |||
| Image src = ImageIO.read(new File(input)); | |||
| int width = src.getWidth(null); // 获取图源宽度 | |||
| int height = src.getHeight(null); // 获取图源高度 | |||
| BufferedImage thumb = new BufferedImage(width / 1, height / 1, | |||
| BufferedImage.TYPE_INT_RGB); | |||
| // 绘制缩小后的图 | |||
| thumb.getGraphics().drawImage(src, 0, 0, width / 1, height / 1, null); | |||
| File file = new File(newFile); // 输出到文件流 | |||
| ImageIO.write(thumb, "jpg", file); | |||
| return file; | |||
| } | |||
| /** | |||
| * 图片上传 | |||
| @@ -209,8 +190,10 @@ public class UploadController extends BaseController { | |||
| } | |||
| fos.close(); | |||
| fs.close(); | |||
| logger.info("local file: " + localImgFileName); | |||
| File newFile = thinImage(localImgFileName, localNewImgFileName); | |||
| File newFile = ImgUtil.thinImage(localImgFileName, localNewImgFileName); | |||
| logger.info("local new file: " + localImgFileName); | |||
| // 删除本地缓存 | |||
| localFile.delete(); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| @@ -16,6 +16,7 @@ import com.iformall.config.AwsProperty; | |||
| import com.iformall.domain.po.MallResource; | |||
| import com.iformall.service.MallResourceService; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.ImgUtil; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.slf4j.Logger; | |||
| @@ -146,24 +147,7 @@ public class UploadController extends BaseController { | |||
| return data; | |||
| } | |||
| /** | |||
| * 图片瘦身 | |||
| * @param input | |||
| * @param newFile | |||
| * @throws Exception | |||
| */ | |||
| private static File thinImage(String input,String newFile) throws IOException { | |||
| Image src = ImageIO.read(new File(input)); | |||
| int width = src.getWidth(null); // 获取图源宽度 | |||
| int height = src.getHeight(null); // 获取图源高度 | |||
| BufferedImage thumb = new BufferedImage(width / 1, height / 1, | |||
| BufferedImage.TYPE_INT_RGB); | |||
| // 绘制缩小后的图 | |||
| thumb.getGraphics().drawImage(src, 0, 0, width / 1, height / 1, null); | |||
| File file = new File(newFile); // 输出到文件流 | |||
| ImageIO.write(thumb, "jpg", file); | |||
| return file; | |||
| } | |||
| /** | |||
| * 图片上传 | |||
| @@ -208,7 +192,7 @@ public class UploadController extends BaseController { | |||
| fos.close(); | |||
| fs.close(); | |||
| File newFile = thinImage(localImgFileName, localNewImgFileName); | |||
| File newFile = ImgUtil.thinImage(localImgFileName, localNewImgFileName); | |||
| // 删除本地缓存 | |||
| localFile.delete(); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||
| @@ -0,0 +1,36 @@ | |||
| package com.iformall.utils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import javax.imageio.ImageIO; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.awt.*; | |||
| import java.awt.image.BufferedImage; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.net.InetAddress; | |||
| import java.net.UnknownHostException; | |||
| public class ImgUtil { | |||
| private final static Logger logger = LoggerFactory.getLogger(ImgUtil.class); | |||
| /** | |||
| * 图片瘦身 | |||
| * @param input | |||
| * @param newFile | |||
| * @throws Exception | |||
| */ | |||
| public static File thinImage(String input, String newFile) throws IOException { | |||
| Image src = ImageIO.read(new File(input)); | |||
| int width = src.getWidth(null); // 获取图源宽度 | |||
| int height = src.getHeight(null); // 获取图源高度 | |||
| BufferedImage thumb = new BufferedImage(width / 1, height / 1, | |||
| BufferedImage.TYPE_INT_RGB); | |||
| // 绘制缩小后的图 | |||
| thumb.getGraphics().drawImage(src, 0, 0, width / 1, height / 1, null); | |||
| File file = new File(newFile); // 输出到文件流 | |||
| ImageIO.write(thumb, "jpg", file); | |||
| return file; | |||
| } | |||
| } | |||
| @@ -17,6 +17,7 @@ import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.MallResource; | |||
| import com.iformall.service.MallResourceService; | |||
| import com.iformall.utils.Constant; | |||
| import com.iformall.utils.ImgUtil; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.slf4j.Logger; | |||
| @@ -28,9 +29,6 @@ import org.springframework.web.bind.annotation.RequestParam; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import javax.imageio.ImageIO; | |||
| import java.awt.*; | |||
| import java.awt.image.BufferedImage; | |||
| import java.io.*; | |||
| import java.net.URL; | |||
| import java.util.*; | |||
| @@ -147,25 +145,6 @@ public class UploadController extends BaseController { | |||
| return data; | |||
| } | |||
| /** | |||
| * 图片瘦身 | |||
| * @param input | |||
| * @param newFile | |||
| * @throws Exception | |||
| */ | |||
| private static File thinImage(String input, String newFile) throws IOException { | |||
| Image src = ImageIO.read(new File(input)); | |||
| int width = src.getWidth(null); // 获取图源宽度 | |||
| int height = src.getHeight(null); // 获取图源高度 | |||
| BufferedImage thumb = new BufferedImage(width / 1, height / 1, | |||
| BufferedImage.TYPE_INT_RGB); | |||
| // 绘制缩小后的图 | |||
| thumb.getGraphics().drawImage(src, 0, 0, width / 1, height / 1, null); | |||
| File file = new File(newFile); // 输出到文件流 | |||
| ImageIO.write(thumb, "jpg", file); | |||
| return file; | |||
| } | |||
| /** | |||
| * 图片上传 | |||
| * | |||
| @@ -209,7 +188,7 @@ public class UploadController extends BaseController { | |||
| fos.close(); | |||
| fs.close(); | |||
| File newFile = thinImage(localImgFileName, localNewImgFileName); | |||
| File newFile = ImgUtil.thinImage(localImgFileName, localNewImgFileName); | |||
| // 删除本地缓存 | |||
| localFile.delete(); | |||
| ObjectMetadata metadata = new ObjectMetadata(); | |||