Skip to content

Instantly share code, notes, and snippets.

@noodlehaus
Created September 2, 2012 01:07
Show Gist options
  • Save noodlehaus/3593035 to your computer and use it in GitHub Desktop.
Save noodlehaus/3593035 to your computer and use it in GitHub Desktop.
function previewImage(file) {
var reader = new FileReader();
reader.onload = function (e) {
var o = $('<img class="img">').attr('src', e.target.result),
r = $('.img-box');
o.load(function (e) {
r.append(o);
var h = o.height(),
w = o.width();
if (w > h && w > 100)
o.width(100);
else if (h > w && h > 100)
o.height(100);
});
};
reader.readAsDataURL(file.files[0]);
}​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment