Skip to content

Commit

Permalink
Remove detectVerticalSquash()
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikolaj committed May 19, 2017
1 parent 2df14f3 commit e8a1f82
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 157 deletions.
58 changes: 8 additions & 50 deletions dist/dropzone-amd-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/

(function() {
var Dropzone, Emitter, camelize, contentLoaded, detectVerticalSquash, drawImageIOSFix, noop, without,
var Dropzone, Emitter, camelize, contentLoaded, noop, without,
__slice = [].slice,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Expand Down Expand Up @@ -129,6 +129,7 @@
url: null,
method: "post",
withCredentials: false,
timeout: 30000,
parallelUploads: 2,
uploadMultiple: false,
maxFilesize: 256,
Expand Down Expand Up @@ -272,7 +273,7 @@
_ref = file.previewElement.querySelectorAll("[data-dz-name]");
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
node = _ref[_i];
node.textContent = this._renameFilename(file.name);
node.textContent = this._renameFilename(file.name, file);
}
_ref1 = file.previewElement.querySelectorAll("[data-dz-size]");
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
Expand Down Expand Up @@ -733,11 +734,11 @@
}
};

Dropzone.prototype._renameFilename = function(name) {
Dropzone.prototype._renameFilename = function(name, file) {
if (typeof this.options.renameFilename !== "function") {
return name;
}
return this.options.renameFilename(name);
return this.options.renameFilename(name, file);
};

Dropzone.prototype.getFallbackForm = function() {
Expand Down Expand Up @@ -1131,7 +1132,7 @@
ctx = canvas.getContext("2d");
canvas.width = resizeInfo.trgWidth;
canvas.height = resizeInfo.trgHeight;
drawImageIOSFix(ctx, img, (_ref = resizeInfo.srcX) != null ? _ref : 0, (_ref1 = resizeInfo.srcY) != null ? _ref1 : 0, resizeInfo.srcWidth, resizeInfo.srcHeight, (_ref2 = resizeInfo.trgX) != null ? _ref2 : 0, (_ref3 = resizeInfo.trgY) != null ? _ref3 : 0, resizeInfo.trgWidth, resizeInfo.trgHeight);
ctx.drawImage(img, (_ref = resizeInfo.srcX) != null ? _ref : 0, (_ref1 = resizeInfo.srcY) != null ? _ref1 : 0, resizeInfo.srcWidth, resizeInfo.srcHeight, (_ref2 = resizeInfo.trgX) != null ? _ref2 : 0, (_ref3 = resizeInfo.trgY) != null ? _ref3 : 0, resizeInfo.trgWidth, resizeInfo.trgHeight);
thumbnail = canvas.toDataURL("image/png");
_this.emit("thumbnail", file, thumbnail);
if (callback != null) {
Expand Down Expand Up @@ -1248,6 +1249,7 @@
Dropzone.prototype.uploadFiles = function(files) {
var file, formData, handleError, headerName, headerValue, headers, i, input, inputName, inputType, key, method, option, progressObj, response, updateProgress, url, value, xhr, _i, _j, _k, _l, _len, _len1, _len2, _len3, _m, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
xhr = new XMLHttpRequest();
xhr.timeout = resolveOption(this.options.timeout, files);
for (_i = 0, _len = files.length; _i < _len; _i++) {
file = files[_i];
file.xhr = xhr;
Expand Down Expand Up @@ -1389,7 +1391,7 @@
}
}
for (i = _m = 0, _ref5 = files.length - 1; 0 <= _ref5 ? _m <= _ref5 : _m >= _ref5; i = 0 <= _ref5 ? ++_m : --_m) {
formData.append(this._getParamName(i), files[i], this._renameFilename(files[i].name));
formData.append(this._getParamName(i), files[i], this._renameFilename(files[i].name, files[i]));
}
return this.submitRequest(xhr, formData, files);
};
Expand Down Expand Up @@ -1666,50 +1668,6 @@
Dropzone.SUCCESS = "success";


/*
Bugfix for iOS 6 and 7
Source: http://stackoverflow.com/questions/11929099/html5-canvas-drawimage-ratio-bug-ios
based on the work of https://github.com/stomita/ios-imagefile-megapixel
*/

detectVerticalSquash = function(img) {
var alpha, canvas, ctx, data, ey, ih, iw, py, ratio, sy;
iw = img.naturalWidth;
ih = img.naturalHeight;
canvas = document.createElement("canvas");
canvas.width = 1;
canvas.height = ih;
ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
data = ctx.getImageData(0, 0, 1, ih).data;
sy = 0;
ey = ih;
py = ih;
while (py > sy) {
alpha = data[(py - 1) * 4 + 3];
if (alpha === 0) {
ey = py;
} else {
sy = py;
}
py = (ey + sy) >> 1;
}
ratio = py / ih;
if (ratio === 0) {
return 1;
} else {
return ratio;
}
};

drawImageIOSFix = function(ctx, img, sx, sy, sw, sh, dx, dy, dw, dh) {
var vertSquashRatio;
vertSquashRatio = detectVerticalSquash(img);
return ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh / vertSquashRatio);
};


/*
* contentloaded.js
*
Expand Down
58 changes: 8 additions & 50 deletions dist/dropzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/

(function() {
var Dropzone, Emitter, camelize, contentLoaded, detectVerticalSquash, drawImageIOSFix, noop, without,
var Dropzone, Emitter, camelize, contentLoaded, noop, without,
__slice = [].slice,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Expand Down Expand Up @@ -117,6 +117,7 @@
url: null,
method: "post",
withCredentials: false,
timeout: 30000,
parallelUploads: 2,
uploadMultiple: false,
maxFilesize: 256,
Expand Down Expand Up @@ -260,7 +261,7 @@
_ref = file.previewElement.querySelectorAll("[data-dz-name]");
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
node = _ref[_i];
node.textContent = this._renameFilename(file.name);
node.textContent = this._renameFilename(file.name, file);
}
_ref1 = file.previewElement.querySelectorAll("[data-dz-size]");
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
Expand Down Expand Up @@ -721,11 +722,11 @@
}
};

Dropzone.prototype._renameFilename = function(name) {
Dropzone.prototype._renameFilename = function(name, file) {
if (typeof this.options.renameFilename !== "function") {
return name;
}
return this.options.renameFilename(name);
return this.options.renameFilename(name, file);
};

Dropzone.prototype.getFallbackForm = function() {
Expand Down Expand Up @@ -1119,7 +1120,7 @@
ctx = canvas.getContext("2d");
canvas.width = resizeInfo.trgWidth;
canvas.height = resizeInfo.trgHeight;
drawImageIOSFix(ctx, img, (_ref = resizeInfo.srcX) != null ? _ref : 0, (_ref1 = resizeInfo.srcY) != null ? _ref1 : 0, resizeInfo.srcWidth, resizeInfo.srcHeight, (_ref2 = resizeInfo.trgX) != null ? _ref2 : 0, (_ref3 = resizeInfo.trgY) != null ? _ref3 : 0, resizeInfo.trgWidth, resizeInfo.trgHeight);
ctx.drawImage(img, (_ref = resizeInfo.srcX) != null ? _ref : 0, (_ref1 = resizeInfo.srcY) != null ? _ref1 : 0, resizeInfo.srcWidth, resizeInfo.srcHeight, (_ref2 = resizeInfo.trgX) != null ? _ref2 : 0, (_ref3 = resizeInfo.trgY) != null ? _ref3 : 0, resizeInfo.trgWidth, resizeInfo.trgHeight);
thumbnail = canvas.toDataURL("image/png");
_this.emit("thumbnail", file, thumbnail);
if (callback != null) {
Expand Down Expand Up @@ -1236,6 +1237,7 @@
Dropzone.prototype.uploadFiles = function(files) {
var file, formData, handleError, headerName, headerValue, headers, i, input, inputName, inputType, key, method, option, progressObj, response, updateProgress, url, value, xhr, _i, _j, _k, _l, _len, _len1, _len2, _len3, _m, _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
xhr = new XMLHttpRequest();
xhr.timeout = resolveOption(this.options.timeout, files);
for (_i = 0, _len = files.length; _i < _len; _i++) {
file = files[_i];
file.xhr = xhr;
Expand Down Expand Up @@ -1377,7 +1379,7 @@
}
}
for (i = _m = 0, _ref5 = files.length - 1; 0 <= _ref5 ? _m <= _ref5 : _m >= _ref5; i = 0 <= _ref5 ? ++_m : --_m) {
formData.append(this._getParamName(i), files[i], this._renameFilename(files[i].name));
formData.append(this._getParamName(i), files[i], this._renameFilename(files[i].name, files[i]));
}
return this.submitRequest(xhr, formData, files);
};
Expand Down Expand Up @@ -1654,50 +1656,6 @@
Dropzone.SUCCESS = "success";


/*
Bugfix for iOS 6 and 7
Source: http://stackoverflow.com/questions/11929099/html5-canvas-drawimage-ratio-bug-ios
based on the work of https://github.com/stomita/ios-imagefile-megapixel
*/

detectVerticalSquash = function(img) {
var alpha, canvas, ctx, data, ey, ih, iw, py, ratio, sy;
iw = img.naturalWidth;
ih = img.naturalHeight;
canvas = document.createElement("canvas");
canvas.width = 1;
canvas.height = ih;
ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
data = ctx.getImageData(0, 0, 1, ih).data;
sy = 0;
ey = ih;
py = ih;
while (py > sy) {
alpha = data[(py - 1) * 4 + 3];
if (alpha === 0) {
ey = py;
} else {
sy = py;
}
py = (ey + sy) >> 1;
}
ratio = py / ih;
if (ratio === 0) {
return 1;
} else {
return ratio;
}
};

drawImageIOSFix = function(ctx, img, sx, sy, sw, sh, dx, dy, dw, dh) {
var vertSquashRatio;
vertSquashRatio = detectVerticalSquash(img);
return ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh / vertSquashRatio);
};


/*
* contentloaded.js
*
Expand Down
3 changes: 1 addition & 2 deletions dist/min/dropzone-amd-module.min.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions dist/min/dropzone.min.js

Large diffs are not rendered by default.

54 changes: 1 addition & 53 deletions src/dropzone.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,7 @@ class Dropzone extends Emitter
canvas.width = resizeInfo.trgWidth
canvas.height = resizeInfo.trgHeight

# This is a bugfix for iOS' scaling bug.
drawImageIOSFix ctx, img, resizeInfo.srcX ? 0, resizeInfo.srcY ? 0, resizeInfo.srcWidth, resizeInfo.srcHeight, resizeInfo.trgX ? 0, resizeInfo.trgY ? 0, resizeInfo.trgWidth, resizeInfo.trgHeight
ctx.drawImage img, resizeInfo.srcX ? 0, resizeInfo.srcY ? 0, resizeInfo.srcWidth, resizeInfo.srcHeight, resizeInfo.trgX ? 0, resizeInfo.trgY ? 0, resizeInfo.trgWidth, resizeInfo.trgHeight

thumbnail = canvas.toDataURL "image/png"

Expand Down Expand Up @@ -1489,57 +1488,6 @@ Dropzone.SUCCESS = "success"





###
Bugfix for iOS 6 and 7
Source: http://stackoverflow.com/questions/11929099/html5-canvas-drawimage-ratio-bug-ios
based on the work of https://github.com/stomita/ios-imagefile-megapixel
###

# Detecting vertical squash in loaded image.
# Fixes a bug which squash image vertically while drawing into canvas for some images.
# This is a bug in iOS6 devices. This function from https://github.com/stomita/ios-imagefile-megapixel
detectVerticalSquash = (img) ->
iw = img.naturalWidth
ih = img.naturalHeight
canvas = document.createElement("canvas")
canvas.width = 1
canvas.height = ih
ctx = canvas.getContext("2d")
ctx.drawImage img, 0, 0
data = ctx.getImageData(0, 0, 1, ih).data


# search image edge pixel position in case it is squashed vertically.
sy = 0
ey = ih
py = ih
while py > sy
alpha = data[(py - 1) * 4 + 3]

if alpha is 0 then ey = py else sy = py

py = (ey + sy) >> 1
ratio = (py / ih)

if (ratio is 0) then 1 else ratio

# A replacement for context.drawImage
# (args are for source and destination).
drawImageIOSFix = (ctx, img, sx, sy, sw, sh, dx, dy, dw, dh) ->
vertSquashRatio = detectVerticalSquash img
ctx.drawImage img, sx, sy, sw, sh, dx, dy, dw, dh / vertSquashRatio








###
# contentloaded.js
#
Expand Down

0 comments on commit e8a1f82

Please sign in to comment.