From 92f1d85ddc449ce7452f9d52f8b081e6b69c720b Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 27 一月 2021 15:29:08 +0800 Subject: [PATCH] update .gitignore --- utils/src/main/java/org/yeshi/utils/ImageCropUtil.java | 158 ++++++++++++++++++++++++++-------------------------- 1 files changed, 79 insertions(+), 79 deletions(-) diff --git a/utils/src/main/java/org/yeshi/utils/ImageCropUtil.java b/utils/src/main/java/org/yeshi/utils/ImageCropUtil.java index dfa0cfa..0239f1b 100644 --- a/utils/src/main/java/org/yeshi/utils/ImageCropUtil.java +++ b/utils/src/main/java/org/yeshi/utils/ImageCropUtil.java @@ -1,79 +1,79 @@ -package org.yeshi.utils; - -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.InputStream; - -import net.coobird.thumbnailator.Thumbnails; -import net.coobird.thumbnailator.Thumbnails.Builder; -import net.coobird.thumbnailator.geometry.Positions; - -/** - * 鍥剧墖瑁佸壀甯姪 - * - * @author Administrator - * - */ -public class ImageCropUtil { - - /** - * 鍓垏鍥剧墖涓棿閮ㄥ垎锛堝唴鍒囷級 - * @param sourceImage - * @param destImage - * @param ratio - * @throws FileNotFoundException - * @throws Exception - */ - public static void centerCrop(InputStream sourceImage, File destImage, float ratio) - throws FileNotFoundException, Exception { - if (sourceImage==null) - throw new FileNotFoundException(); - - BufferedImage image = Thumbnails.of(sourceImage).scale(1.0f).asBufferedImage(); - int width = image.getWidth(); - int height = image.getHeight(); - int newWidth = 0; - int newHeight = 0; - if (width > ratio * height) {// 浠ラ珮涓轰富 - newHeight = height; - newWidth = (int) (newHeight * ratio); - } else {// 浠ュ涓轰富 - newWidth = width; - newHeight = (int) (newWidth / ratio); - } - - if (destImage.exists()) - destImage.delete(); - - Thumbnails.of(sourceImage).sourceRegion(Positions.CENTER, newWidth, newHeight).scale(1.0) - .toFile(destImage.getPath()); - } - - - public static void centerCrop(File sourceImage, File destImage, float ratio) - throws FileNotFoundException, Exception { - if (sourceImage==null) - throw new FileNotFoundException(); - - BufferedImage image = Thumbnails.of(sourceImage).scale(1.0f).asBufferedImage(); - int width = image.getWidth(); - int height = image.getHeight(); - int newWidth = 0; - int newHeight = 0; - if (width > ratio * height) {// 浠ラ珮涓轰富 - newHeight = height; - newWidth = (int) (newHeight * ratio); - } else {// 浠ュ涓轰富 - newWidth = width; - newHeight = (int) (newWidth / ratio); - } - - if (destImage.exists()) - destImage.delete(); - - Thumbnails.of(sourceImage).sourceRegion(Positions.CENTER, newWidth, newHeight).scale(1.0) - .toFile(destImage.getPath()); - } - -} +package org.yeshi.utils; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.InputStream; + +import net.coobird.thumbnailator.Thumbnails; +import net.coobird.thumbnailator.Thumbnails.Builder; +import net.coobird.thumbnailator.geometry.Positions; + +/** + * 鍥剧墖瑁佸壀甯姪 + * + * @author Administrator + * + */ +public class ImageCropUtil { + + /** + * 鍓垏鍥剧墖涓棿閮ㄥ垎锛堝唴鍒囷級 + * @param sourceImage + * @param destImage + * @param ratio + * @throws FileNotFoundException + * @throws Exception + */ + public static void centerCrop(InputStream sourceImage, File destImage, float ratio) + throws FileNotFoundException, Exception { + if (sourceImage==null) + throw new FileNotFoundException(); + + BufferedImage image = Thumbnails.of(sourceImage).scale(1.0f).asBufferedImage(); + int width = image.getWidth(); + int height = image.getHeight(); + int newWidth = 0; + int newHeight = 0; + if (width > ratio * height) {// 浠ラ珮涓轰富 + newHeight = height; + newWidth = (int) (newHeight * ratio); + } else {// 浠ュ涓轰富 + newWidth = width; + newHeight = (int) (newWidth / ratio); + } + + if (destImage.exists()) + destImage.delete(); + + Thumbnails.of(sourceImage).sourceRegion(Positions.CENTER, newWidth, newHeight).scale(1.0) + .toFile(destImage.getPath()); + } + + + public static void centerCrop(File sourceImage, File destImage, float ratio) + throws FileNotFoundException, Exception { + if (sourceImage==null) + throw new FileNotFoundException(); + + BufferedImage image = Thumbnails.of(sourceImage).scale(1.0f).asBufferedImage(); + int width = image.getWidth(); + int height = image.getHeight(); + int newWidth = 0; + int newHeight = 0; + if (width > ratio * height) {// 浠ラ珮涓轰富 + newHeight = height; + newWidth = (int) (newHeight * ratio); + } else {// 浠ュ涓轰富 + newWidth = width; + newHeight = (int) (newWidth / ratio); + } + + if (destImage.exists()) + destImage.delete(); + + Thumbnails.of(sourceImage).sourceRegion(Positions.CENTER, newWidth, newHeight).scale(1.0) + .toFile(destImage.getPath()); + } + +} -- Gitblit v1.8.0