Browse Source

small image generator improve

master
filesite 4 months ago
parent
commit
53b43323be
  1. 11
      www/js/beauty.js

11
www/js/beauty.js

@ -23,9 +23,10 @@ if ($('#image_site').get(0)) { @@ -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)) { @@ -33,8 +34,14 @@ if ($('#image_site').get(0)) {
var aspect = naturalHeight / naturalWidth;
var canvas = document.createElement('canvas');
canvas.width = width * 1.5;
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 );

Loading…
Cancel
Save