|
|
@ -21,18 +21,20 @@ if ($('#image_site').get(0)) { |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
//需要浏览器支持naturalWidth
|
|
|
|
//需要浏览器支持naturalWidth
|
|
|
|
var saveSmallImg = function(imgEl) { |
|
|
|
var saveSmallImg = function(imgEl, cateId) { |
|
|
|
var width = imgEl.width, |
|
|
|
var width = imgEl.width, |
|
|
|
naturalWidth = imgEl.naturalWidth, |
|
|
|
naturalWidth = imgEl.naturalWidth, |
|
|
|
naturalHeight = imgEl.naturalHeight; |
|
|
|
naturalHeight = imgEl.naturalHeight; |
|
|
|
if (!naturalWidth || naturalWidth - width < 100) {return false;} |
|
|
|
if (!naturalWidth || naturalWidth - width < 100 || |
|
|
|
|
|
|
|
(typeof(disableSmallImage) != 'undefined' && disableSmallImage) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var aspect = naturalHeight / naturalWidth; |
|
|
|
var aspect = naturalHeight / naturalWidth; |
|
|
|
|
|
|
|
|
|
|
|
var canvas = document.createElement('canvas'); |
|
|
|
var canvas = document.createElement('canvas'); |
|
|
|
|
|
|
|
canvas.width = width * 1.5; |
|
|
|
canvas.width = width; |
|
|
|
canvas.height = canvas.width * aspect; |
|
|
|
canvas.height = width * aspect; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ctx = canvas.getContext('2d'); |
|
|
|
var ctx = canvas.getContext('2d'); |
|
|
|
ctx.drawImage( imgEl, 0, 0, canvas.width, canvas.height ); |
|
|
|
ctx.drawImage( imgEl, 0, 0, canvas.width, canvas.height ); |
|
|
@ -45,6 +47,9 @@ if ($('#image_site').get(0)) { |
|
|
|
id: $(imgEl).attr('data-id'), |
|
|
|
id: $(imgEl).attr('data-id'), |
|
|
|
data: smallImg |
|
|
|
data: smallImg |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
if (typeof(cateId) != 'undefined' && cateId) { |
|
|
|
|
|
|
|
params.pid = cateId; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
$.ajax({ |
|
|
|
url: '/site/savesmallimg', |
|
|
|
url: '/site/savesmallimg', |
|
|
@ -218,7 +223,7 @@ $('.dir_item').each(function(index, el) { |
|
|
|
setTimeout(function() { |
|
|
|
setTimeout(function() { |
|
|
|
var imgs = $(el).find('.im_img'); |
|
|
|
var imgs = $(el).find('.im_img'); |
|
|
|
if (imgs.length > 0) { |
|
|
|
if (imgs.length > 0) { |
|
|
|
saveSmallImg(imgs[0]); |
|
|
|
saveSmallImg(imgs[0], id); |
|
|
|
} |
|
|
|
} |
|
|
|
}, 100); |
|
|
|
}, 100); |
|
|
|
} |
|
|
|
} |
|
|
|