Test: Image width and height

by aburayane

HTML

<div class="originImg" id="originImg1">
        <div class="upImage" id="up1">
            <label for="file-input1">
                <img src="https://cdn3.iconfinder.com/data/icons/blackblue/128/iPhoto.png" id="file1">
            </label>
        
            <input id="file-input1" name="uploads[]" type="file"/>
        </div>
        
        <!-- Single upload image info and errors -->
        
        <div class="upInfoError" id="up1InfoError" style="float: left; padding-left: 20px;">
            <div class="upInfo" id="up1Info">
               
                </div>
                
            <div style="width: 350px; display: inline-block;">
                    <div style="float:left; padding-right: 10px;">
                        <div class="progressBarContainer" id="progressBarContainer1">
                        <span class="progressBarWrap" id="progressBarWrap1"></span>
                    </div>
                
                    <div class="progressBarPercent" id="progressBarPercent1">0%</div>
                    </div>
                    <div style="float:left; width: auto;">
                        <button class="progressBarCancel" id="progressBarCancel1" style="display: none;">Cancel</button>
                    </div>
                </div>
                
                <div class="progressBarCount" id="progressBarCount1">0KB</div>
                
            <div class="upError" id="up1Error">Error here</div>    
                
            
            </div>

        </div>

CSS

/* Upload image Start */
.origin {
  width: auto;
  border: 1px solid gray;
  display: inline-block;
}

.upImage > input
{
    display: none;
}

.upImage img {
    width: 100px;
    height: 100px;
    cursor: pointer;
}

.upImage{
    border: 2px dotted gray;
    width: 100px;
    height: 100px;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    float: left;
    margin: 5px;
}
	
.upInfo{
    border: 0px solid gray;
    width: 90px;
    height: auto;
    float: left;
    margin: 10px;
    text-align: center;
    
}
/* Upload image EnD */

JavaScript

function checkFiles(fileID, targetID){
 
 var fileWidth       = $('#'+targetID).prop("naturalWidth");
        var fileHeight      = $('#'+targetID).prop("naturalHeight");
        
 /*
var fileWidth  = $('#'+targetID).prop("naturalWidth")  || $('#'+targetID).width();
var fileHeight = $('#'+targetID).prop("naturalHeight") || $('#'+targetID).height();
*/
alert(fileWidth+'x'+fileHeight);
        
        
} // end function

function readURL(inptID, targetID){

	var file = $('#'+inptID).prop('files');

        // display file object
        var fileAttributes  = file[0];

        // display file value (including path)
        var path = $('#'+inptID).val();
        // split the file value
        var pathSpl = $('#'+inptID).val().split('.');
        // display the length of the splitted value
        var pathSplLen  = pathSpl.length;
        var fileExt = pathSpl.pop().toLowerCase();
        var types = typeof (FileReader);
        var reader = new FileReader();
 
        reader.onload = function (e) {

        $('#'+targetID).attr('src', e.target.result);
        } // end function 

        // read the data as URL
        reader.readAsDataURL(file[0]);


  
  } // end function readURL
  
  
$('.upImage').on('change', function(){
// get file input ID
var fileID	= $(this).find('input').attr('id');
//console.log(fileID);
 
// get image ID (where to preview the image)
var imgID       = $(this).find("img").attr('id');
        
var uploadFile = checkFiles(fileID, imgID);
   
   readURL(fileID, imgID);


});