From 53b43323be60ef15a8313c68417fa5c67525f5c7 Mon Sep 17 00:00:00 2001 From: filesite Date: Wed, 17 Jul 2024 23:11:54 +0800 Subject: [PATCH] small image generator improve --- www/js/beauty.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/www/js/beauty.js b/www/js/beauty.js index 888699a..3979da1 100644 --- a/www/js/beauty.js +++ b/www/js/beauty.js @@ -23,9 +23,10 @@ if ($('#image_site').get(0)) { //需要浏览器支持naturalWidth var saveSmallImg = function(imgEl, cateId) { var width = imgEl.width, + height = imgEl.height, naturalWidth = imgEl.naturalWidth, naturalHeight = imgEl.naturalHeight; - if (!naturalWidth || naturalWidth - width < 100 || + if (!naturalWidth || naturalWidth < 600 || naturalHeight < 500 || (typeof(disableSmallImage) != 'undefined' && disableSmallImage) ) { return false; @@ -33,8 +34,14 @@ if ($('#image_site').get(0)) { var aspect = naturalHeight / naturalWidth; var canvas = document.createElement('canvas'); - canvas.width = width * 1.5; - canvas.height = canvas.width * aspect; + + if (naturalWidth <= naturalHeight) { + canvas.width = width * 2.5 <= 600 ? width * 2.5 : 600; + canvas.height = canvas.width * aspect; + }else { + canvas.height = height * 2.5 <= 500 ? height * 2.5 : 500; + canvas.width = canvas.height / aspect; + } var ctx = canvas.getContext('2d'); ctx.drawImage( imgEl, 0, 0, canvas.width, canvas.height );