I am new here so please bear with me! I have used another script I found on SO where a small 50 pixel thumbnail image is displayed in the browser after a user selects the browse button and chooses an image.
The HTML of the form look like:
<input type='file' onchange="readURL(this);" />
<img id="blah" src="http://openglobaldirectory.com/images/default_profile.gif" width="50" alt="your image" />
And I have a JavaScript function that looks like:
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah')
.attr('src', e.target.result)
.width(50)
.height(50);
};
reader.readAsDataURL(input.files[0]);
}
}
When the user selects the image from the file the 50x50px thumbnail displays in the page however, it will compress the whole image and unless the image selected is a square (or almost square) the thumbnail generated looks very distorted.
What I would like to do is create a cleaner thumbnail that will not display a distorted or compressed image, regardless of the size of the original. I suppose what will need to happen is to first bring the height of the image down to 50px and then take thumbnail based on the 50px worth of image in the middle.
Does anyone know a way to do this?
Btw the original script I am following as an example can be found here: HTML - Display image after selecting filename