Check image size, #16
This commit is contained in:
parent
66e1e23e6a
commit
49f1ef529d
@ -5988,12 +5988,46 @@
|
||||
QR.cleanNotifications();
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
file = files[_i];
|
||||
QR.handleFile(file, isSingle, max);
|
||||
QR.checkDimensions(file, isSingle, max);
|
||||
}
|
||||
if (!isSingle) {
|
||||
return $.addClass(QR.nodes.el, 'dump');
|
||||
}
|
||||
},
|
||||
checkDimensions: function(file, isSingle, max) {
|
||||
var img,
|
||||
_this = this;
|
||||
img = new Image();
|
||||
img.onload = function() {
|
||||
var height, width;
|
||||
height = img.height, width = img.width;
|
||||
if (g.BOARD.ID === 'hr') {
|
||||
if (height > 10000 || width > 10000) {
|
||||
return QR.error("" + file.name + ": Image too large (image: " + img.height + "x" + img.width + "px, max: 10000x10000px");
|
||||
}
|
||||
}
|
||||
if (g.BOARD.ID === 'hr') {
|
||||
if (height < 1000 || width < 1000) {
|
||||
return QR.error("" + file.name + ": Image too small (image: " + img.height + "x" + img.width + "px, min: 1000x1000px");
|
||||
}
|
||||
}
|
||||
if (g.BOARD.ID === 'wg') {
|
||||
if (height < 480 || width < 600) {
|
||||
return QR.error("" + file.name + ": Image too small (image: " + img.height + "x" + img.width + "px, min: 480x600px");
|
||||
}
|
||||
}
|
||||
if (g.BOARD.ID === 'w') {
|
||||
if (height < 480 || width < 600) {
|
||||
return QR.error("" + file.name + ": Image too small (image: " + img.height + "x" + img.width + "px, min: 480x600px");
|
||||
}
|
||||
}
|
||||
if (height > 5000 || width > 5000) {
|
||||
return QR.error("" + file.name + ": Image too large (image: " + img.height + "x" + img.width + "px, max: 5000x5000px");
|
||||
}
|
||||
return QR.handleFile(file, isSingle, max);
|
||||
};
|
||||
return img.src = URL.createObjectURL(file);
|
||||
},
|
||||
handleFile: function(file, isSingle, max) {
|
||||
var post, _ref;
|
||||
if (file.size > max) {
|
||||
|
||||
@ -6024,12 +6024,46 @@
|
||||
QR.cleanNotifications();
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
file = files[_i];
|
||||
QR.handleFile(file, isSingle, max);
|
||||
QR.checkDimensions(file, isSingle, max);
|
||||
}
|
||||
if (!isSingle) {
|
||||
return $.addClass(QR.nodes.el, 'dump');
|
||||
}
|
||||
},
|
||||
checkDimensions: function(file, isSingle, max) {
|
||||
var img,
|
||||
_this = this;
|
||||
img = new Image();
|
||||
img.onload = function() {
|
||||
var height, width;
|
||||
height = img.height, width = img.width;
|
||||
if (g.BOARD.ID === 'hr') {
|
||||
if (height > 10000 || width > 10000) {
|
||||
return QR.error("" + file.name + ": Image too large (image: " + img.height + "x" + img.width + "px, max: 10000x10000px");
|
||||
}
|
||||
}
|
||||
if (g.BOARD.ID === 'hr') {
|
||||
if (height < 1000 || width < 1000) {
|
||||
return QR.error("" + file.name + ": Image too small (image: " + img.height + "x" + img.width + "px, min: 1000x1000px");
|
||||
}
|
||||
}
|
||||
if (g.BOARD.ID === 'wg') {
|
||||
if (height < 480 || width < 600) {
|
||||
return QR.error("" + file.name + ": Image too small (image: " + img.height + "x" + img.width + "px, min: 480x600px");
|
||||
}
|
||||
}
|
||||
if (g.BOARD.ID === 'w') {
|
||||
if (height < 480 || width < 600) {
|
||||
return QR.error("" + file.name + ": Image too small (image: " + img.height + "x" + img.width + "px, min: 480x600px");
|
||||
}
|
||||
}
|
||||
if (height > 5000 || width > 5000) {
|
||||
return QR.error("" + file.name + ": Image too large (image: " + img.height + "x" + img.width + "px, max: 5000x5000px");
|
||||
}
|
||||
return QR.handleFile(file, isSingle, max);
|
||||
};
|
||||
return img.src = URL.createObjectURL(file);
|
||||
},
|
||||
handleFile: function(file, isSingle, max) {
|
||||
var post, _ref;
|
||||
if (file.size > max) {
|
||||
|
||||
@ -355,9 +355,25 @@ QR =
|
||||
isSingle = files.length is 1
|
||||
QR.cleanNotifications()
|
||||
for file in files
|
||||
QR.handleFile file, isSingle, max
|
||||
QR.checkDimensions file, isSingle, max
|
||||
$.addClass QR.nodes.el, 'dump' unless isSingle
|
||||
|
||||
checkDimensions: (file, isSingle, max) ->
|
||||
img = new Image()
|
||||
img.onload = =>
|
||||
{height, width} = img
|
||||
if g.BOARD.ID is 'hr'
|
||||
return QR.error "#{file.name}: Image too large (image: #{img.height}x#{img.width}px, max: 10000x10000px" if height > 10000 or width > 10000
|
||||
if g.BOARD.ID is 'hr'
|
||||
return QR.error "#{file.name}: Image too small (image: #{img.height}x#{img.width}px, min: 1000x1000px" if height < 1000 or width < 1000
|
||||
if g.BOARD.ID is 'wg'
|
||||
return QR.error "#{file.name}: Image too small (image: #{img.height}x#{img.width}px, min: 480x600px" if height < 480 or width < 600
|
||||
if g.BOARD.ID is 'w'
|
||||
return QR.error "#{file.name}: Image too small (image: #{img.height}x#{img.width}px, min: 480x600px" if height < 480 or width < 600
|
||||
return QR.error "#{file.name}: Image too large (image: #{img.height}x#{img.width}px, max: 5000x5000px" if height > 5000 or width > 5000
|
||||
QR.handleFile file, isSingle, max
|
||||
img.src = URL.createObjectURL file
|
||||
|
||||
handleFile: (file, isSingle, max) ->
|
||||
if file.size > max
|
||||
QR.error "#{file.name}: File too large (file: #{$.bytesToString file.size}, max: #{$.bytesToString max})."
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user