From 814aa3d662da7f781bf25fb0b4fa5d0ea7fbba01 Mon Sep 17 00:00:00 2001 From: Looly Date: Sat, 16 Nov 2019 06:01:49 +0800 Subject: [PATCH] fix scale with bg --- CHANGELOG.md | 1 + .../src/main/java/cn/hutool/core/img/Img.java | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9feb0792c..adcf84bfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ ### Bug修复 * 【core】 修复DateUtil.format使用DateTime时区失效问题(issue#I150I7@Gitee) * 【core】 修复ZipUtil解压目录遗留问题(issue#I14NO3@Gitee) +* 【core】 修复等比缩放给定背景色无效问题(pr#625@Github) ------------------------------------------------------------------------------------------------------------- diff --git a/hutool-core/src/main/java/cn/hutool/core/img/Img.java b/hutool-core/src/main/java/cn/hutool/core/img/Img.java index 83c0c6160..c52182bb3 100644 --- a/hutool-core/src/main/java/cn/hutool/core/img/Img.java +++ b/hutool-core/src/main/java/cn/hutool/core/img/Img.java @@ -279,14 +279,14 @@ public class Img implements Serializable { double widthRatio = NumberUtil.div(width, srcWidth); if (heightRatio == widthRatio) { // 长宽都按照相同比例缩放时,返回缩放后的图片 - return scale(width, height); - } - - // 宽缩放比例多就按照宽缩放,否则按照高缩放 - if (widthRatio < heightRatio) { - scale(width, (int) (srcHeight * widthRatio)); - } else { - scale((int) (srcWidth * heightRatio), height); + scale(width, height); + } else{ + // 宽缩放比例多就按照宽缩放,否则按照高缩放 + if (widthRatio < heightRatio) { + scale(width, (int) (srcHeight * widthRatio)); + } else { + scale((int) (srcWidth * heightRatio), height); + } } // 获取缩放后的新的宽和高