Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate a thumbnail image from an onload
    primarykey
    data
    text
    <p>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.</p> <p>The HTML of the form look like:</p> <pre><code>&lt;input type='file' onchange="readURL(this);" /&gt; &lt;img id="blah" src="http://openglobaldirectory.com/images/default_profile.gif" width="50" alt="your image" /&gt; </code></pre> <p>And I have a JavaScript function that looks like:</p> <pre><code>function readURL(input) { if (input.files &amp;&amp; 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]); } } </code></pre> <p>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.</p> <p>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.</p> <p>Does anyone know a way to do this?</p> <p>Btw the original script I am following as an example can be found here: <a href="https://stackoverflow.com/questions/12368910/html-display-image-after-selecting-filename">HTML - Display image after selecting filename</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload