4

Im using this javascript code to show selected image to upload:

    var input = document.getElementById("images"), 
    formdata = false;

function showUploadedItem (source) {
    var list = document.getElementById("image-list"),
        li   = document.createElement("li"),
        img  = document.createElement("img");
    img.src = source;
    li.appendChild(img);
    list.appendChild(li);
}  

HTML:

 <span class="span4">
   <div id="response"></div>
   <ul id="image-list">
   </ul>
 </span> 

How can I edit the code so the image selected and is showed is showed with 400px insted of orginal size. Example:

Thanks!

Chris
  • 65
  • 2
  • 10

6 Answers6

6

You can say:

img.style.width = "400px";
img.style.height = "400px";
Petr Gazarov
  • 3,340
  • 2
  • 16
  • 33
0

CSS:

#image-list img{
   height: 400px;
   width: auto;
}

if you really want to physically resize your image... than if your image is on your server you could send it to canvas, perform a resize and serve it as base64 encoded string...

Interesting reading: How to Preview Image, get file size, image height and width before upload?

Community
  • 1
  • 1
Roko C. Buljan
  • 180,066
  • 36
  • 283
  • 292
0

You can use style to set width and height in %:

img.style.width="100%";
Ajay Venkata Raju
  • 1,036
  • 9
  • 22
-1

You could also add a css class (resize) to this images

img.resize{
    width:540px; /* you can use % */
    height: auto;
}
Nicholas
  • 3,049
  • 1
  • 22
  • 30
-1

By including the lines...

img.style.width='400px';

img.style.height='400px';

Or whatever size you wanted.

-2

After the creation of your object img, you can use something like:

img.width = "400";
img.height = "400";
Rodrigo Juarez
  • 843
  • 1
  • 7
  • 17