|
|
|
@ -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; |
|
|
|
|
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 ); |
|
|
|
|