//读取图片
InputStream inputStream = file.getInputStream();
BufferedImage image = ImgUtil.read(inputStream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
//压缩图片,将大于1080p的图片压缩到1080p
int w = image.getWidth();
image = image.getWidth() > 1080 ? toBufferedImage(scale(image, 1080f / w)) : image;
//添加水印
String datetime = LocalDateTime.now().format(DATETIME_FORMAT);
int x = 0;
int y = image.getHeight() * 9 / 20;
ImgUtil.pressText(image, outputStream, datetime, LIGHT_GRAY, new Font(MONOSPACED, BOLD, 30), x, y, .7f);
byte[] bytes = outputStream.toByteArray();
网友评论