Restrict image height and width using J Query is very essay. find image upload event using "change" Event. Get image value using "val".
The Below code is very useful to all.
J Query Code
----------------------
$(function() {
var _URL = window.URL || window.webkitURL;
$("#gal_thumb_image").change(function(e) {
var gal_thumb_image, img;
if ((gal_thumb_image = this.files[0])) {
img = new Image();
img.onload = function() {
if(this.width!==250 || this.height!==250){
alert("Image size should be 250*250");
$('#gal_thumb_image').val('');
return false;
}
alert
};
img.onerror = function() {
alert( "not a valid gal_thumb_image: " + gal_thumb_image.type);
};
img.src = _URL.createObjectURL(gal_thumb_image);
}
});
});
HTML Code
---------------------
<input type="file" id="gal_thumb_image" name="gal_thumb_image"/>
The Below code is very useful to all.
J Query Code
----------------------
$(function() {
var _URL = window.URL || window.webkitURL;
$("#gal_thumb_image").change(function(e) {
var gal_thumb_image, img;
if ((gal_thumb_image = this.files[0])) {
img = new Image();
img.onload = function() {
if(this.width!==250 || this.height!==250){
alert("Image size should be 250*250");
$('#gal_thumb_image').val('');
return false;
}
alert
};
img.onerror = function() {
alert( "not a valid gal_thumb_image: " + gal_thumb_image.type);
};
img.src = _URL.createObjectURL(gal_thumb_image);
}
});
});
HTML Code
---------------------
<input type="file" id="gal_thumb_image" name="gal_thumb_image"/>