7

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
  • 105
  • 3
  • 10

6 Answers6

9

You can say:

img.style.width = "400px";
img.style.height = "400px";
Petr Gazarov
  • 3,602
  • 2
  • 20
  • 37
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
  • 196,159
  • 39
  • 305
  • 313
0

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

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

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

img.resize{
    width:540px; /* you can use % */
    height: auto;
}
Nicholas
  • 3,529
  • 2
  • 23
  • 31
-1

By including the lines...

img.style.width='400px';

img.style.height='400px';

Or whatever size you wanted.

user6245342
  • 108
  • 3
-2

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

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