In a few minutes looking for a way to show an preview of an image before uploading it, I found the great solution:
$("##ID DO INPUT FILE##").change(function (event) {
var reader = new FileReader();
$(reader).load(function (event) {
$("##ID DO ELEMENTO IMG##").attr("src", event.target.result);
});
reader.readAsDataURL(event.target.files[0]);
});
However, I use a imageresizing.net library that wanted to use one of its features so that preview is displayed with crop and center-aligned.
In my case I am using the code below and I was not successful because the output of the image is a base64
function readfile(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#image_preview').attr('src', e.target.result);
};
reader.readAsDataURL(input.files[0] + "?w=340&h=260&mod=crop&format=png");
}
}
$("#upload").change(function() {
readfile(this);
});
Is there any other way to show preview where I can take advantage of imageresizing ?