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