浏览代码

fix scale with bg

Looly 6 年之前
父节点
当前提交
814aa3d662
共有 2 个文件被更改,包括 9 次插入8 次删除
  1. 1 0
      CHANGELOG.md
  2. 8 8
      hutool-core/src/main/java/cn/hutool/core/img/Img.java

+ 1 - 0
CHANGELOG.md

@@ -13,6 +13,7 @@
 ### Bug修复
 ### Bug修复
 * 【core】       修复DateUtil.format使用DateTime时区失效问题(issue#I150I7@Gitee)
 * 【core】       修复DateUtil.format使用DateTime时区失效问题(issue#I150I7@Gitee)
 * 【core】       修复ZipUtil解压目录遗留问题(issue#I14NO3@Gitee)
 * 【core】       修复ZipUtil解压目录遗留问题(issue#I14NO3@Gitee)
+* 【core】       修复等比缩放给定背景色无效问题(pr#625@Github)
 
 
 -------------------------------------------------------------------------------------------------------------
 -------------------------------------------------------------------------------------------------------------
 
 

+ 8 - 8
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);
 		double widthRatio = NumberUtil.div(width, srcWidth);
 		if (heightRatio == widthRatio) {
 		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);
+			}
 		}
 		}
 
 
 		// 获取缩放后的新的宽和高
 		// 获取缩放后的新的宽和高