I have the following code
var inputLocalFont = document.getElementById("image-input");
inputLocalFont.addEventListener("change",previewImages,false);
function previewImages(){
var fileList = this.files;
var anyWindow = window.URL || window.webkitURL;
for(var i = 0; i < fileList.length; i++){
var objectUrl = anyWindow.createObjectURL(fileList[i]);
$('.preview-area').append('<img class="resizeme" id="myImage" height="150" src="' + objectUrl + '" + title="' + fileList[i].name + ' ( ' + fileList[i] + ' "/>');
window.URL.revokeObjectURL(fileList[i]);
}
}
i can get image name for title by this code
fileList[i].name
but when i try to add width and height in title image by adding this code
fileList[i].width
fileList[i].height
it's give "undefined" result
i already try using fileList[i].naturalWidth
and it's give same result
what I'm missing?
FLOW
i try to created a multiple image preview before user press submit and upload image to server...i want every preview image has tooltip title which contains (name, width, height)
i already success get name in tooltip by
fileList[i].name
is it possible to get width and height of image too in tooltip title?
ADD EVENT LISTENER INSIDE LOOP
var inputLocalImage = document.getElementById("image-input");
inputLocalImage.addEventListener("change",previewImages,false);
function previewImages(){
var fileList = this.files;
var anyWindow = window.URL || window.webkitURL;
for(var i = 0; i < fileList.length; i++){
var objectUrl = anyWindow.createObjectURL(fileList[i]);
objectUrl.addEventListener("load", function() {
alert('objectUrl.width');
})
$('.preview-area').append('<img class="resizeme" id="myImage" height="150" src="' + objectUrl + '" + title="' + fileList[i].name + ' (s ' + fileList[i].clientWidth + ' "/>');
window.URL.revokeObjectURL(fileList[i]);
}
}
I already try add event listener in
objectUrl / filename[i]
with property
.width
.naturalWidth
.clientWidth
What I'm missing?
HTML
<div class="row">
<label for="image" class="control-label col-lg-3">Image<span class="required">*</span></label>
<div class="col-lg-8">
<input type="file" class="dimmy" id="image-input" multiple />
<div class="preview-area"></div>
</div>
</div>
preview-area class is my container for multiple image preview...i append it by this code
$('.preview-area').append('<img class="resizeme" id="myImage" height="150" src="' + objectUrl + '" + title="' + fileList[i].name + ' ( ' + fileList[i] + ' "/>');