Skip to content

Commit

Permalink
Auto orientation image parsing for portrait fixes #952
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Apr 30, 2017
1 parent 8872c72 commit 72065d9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
4 changes: 4 additions & 0 deletions css/fileinput.css
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,8 @@

.rotate-8 {
transform: rotate(270deg);
}

.file-zoom-content .is-portrait-gt4 {
margin-top: 60px;
}
2 changes: 1 addition & 1 deletion css/fileinput.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions js/fileinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@
$h.setOrientation(buffer, callback);
};
reader.readAsArrayBuffer(file);
},
adjustOrientedImage: function($img, isZoom) {
var offsetContTop, offsetTop, newTop;
if (!$img.hasClass('is-portrait-gt4')) {
return;
}
if (isZoom) {
$img.css({width: $img.parent().height()});
return;
} else {
$img.css({height: 'auto', width: $img.height()});
}
offsetContTop = $img.parent().offset().top;
offsetTop = $img.offset().top;
newTop = offsetContTop - offsetTop;
$img.css('margin-top', newTop);
}
};
FileInput = function (element, options) {
Expand Down Expand Up @@ -1416,6 +1432,10 @@
});
}
$modal.data('previewId', pid);
var $img = $body.find('img');
if ($img.length) {
$h.adjustOrientedImage($img, true);
}
self._handler($prev, 'click', function () {
self._zoomSlideShow('prev', pid);
});
Expand Down Expand Up @@ -2400,11 +2420,15 @@
$h.validateOrientation(file, function (value) {
if (value) {
var $zoomImg = $preview.find('#zoom-' + previewId + ' img'), css = 'rotate-' + value;
if (value > 4) {
css += ($img.width() > $img.height() ? ' is-portrait-gt4' : ' is-landscape-gt4');
}
$h.addCss($img, css);
$h.addCss($zoomImg, css);
self._raise('fileimageoriented', {'$img': $img, 'file': file});
}
self._validateImage(previewId, caption, ftype, fsize);
$h.adjustOrientedImage($img);
});
} else {
self._validateImage(previewId, caption, ftype, fsize);
Expand Down
6 changes: 3 additions & 3 deletions js/fileinput.min.js

Large diffs are not rendered by default.

0 comments on commit 72065d9

Please sign in to comment.