You've already forked FrameTour-BE
下载不需要水印
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.ycwl.basic.utils;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -12,6 +13,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
@Slf4j
|
||||
public class ImageUtils {
|
||||
public static MultipartFile base64ToMultipartFile(String base64) {
|
||||
String[] baseStrs = base64.split(",");
|
||||
@@ -27,10 +29,12 @@ public class ImageUtils {
|
||||
|
||||
public static MultipartFile cropImage(MultipartFile file, int x, int y, int w, int h) throws IOException {
|
||||
BufferedImage image = ImageIO.read(file.getInputStream());
|
||||
if (image.getWidth() > w) {
|
||||
log.info("图片宽高:{}", image.getWidth() + "x" + image.getHeight());
|
||||
log.info("图片裁切:{}@{}", w + "x" + h, x + "," + y);
|
||||
if (image.getWidth() < w) {
|
||||
w = image.getWidth();
|
||||
}
|
||||
if (image.getHeight() > h) {
|
||||
if (image.getHeight() < h) {
|
||||
h = image.getHeight();
|
||||
}
|
||||
int targetX = x;
|
||||
@@ -45,6 +49,7 @@ public class ImageUtils {
|
||||
} else if ((y + h) > image.getHeight()) {
|
||||
targetY = image.getHeight() - h;
|
||||
}
|
||||
log.info("图片实际裁切:{}@{}", w + "x" + h, targetX + "," + targetY);
|
||||
BufferedImage targetImage = image.getSubimage(targetX, targetY, w, h);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(targetImage, "jpg", baos);
|
||||
|
Reference in New Issue
Block a user