Reputation: 21
how i get uploaded image height and width,for display in it's original size.
Upvotes: 1
Views: 8543
Reputation: 11213
If you dont specify a height and width the img tag will display an image in its correct size
the following will display mypic.jpg full size
<img src='mypic.jpg' >
or this will display the image with width 200px and height in ratio
<img src='mypic.jpg' width="200px" >
Upvotes: 0
Reputation: 482
getimagesize should do the trick, check this out for more documentation http://php.net/manual/en/function.getimagesize.php
Upvotes: 1
Reputation: 104780
The image will render in its 'natural' size if the img tag has no width and height attribute and the css does not define style width and height for it.
Upvotes: 0
Reputation: 20115
If you use the Prototype Javascript library:
var img = new Element(
'img', {
src: 'image.jpg'
}
);
img.observe(
'load',
function(event) {
alert(
Event.element(event).getWidth() +
'x' +
Event.element(event).getHeight()
);
}
);
$$('body').first().appendChild(img);
img.remove();
Upvotes: 0
Reputation: 101604
In a case of client-size, you can use the following:
;(function($){
$.imageSize = function(imgUrl,callback){
var img = $('<img>').attr('src',imgUrl).css('display','none').appendTo('body');
img.load(function(){
var call = callback || function(i,w,h){};
call(imgUrl,$(this).width(),$(this).height());
});
};
})(jQuery);
(jQuery plugin) You can't get the image size until it's been loaded, but if you load it up in the background and wait for it, you'll be able to access the information. e.g.
$.imageSize('http://www.nasa.gov/images/content/511786main_image_1848_946-710.jpg',function(i,w,h){
alert(i+'\r\n'+w+'x'+h);
});
Upvotes: 1
Reputation: 11210
Keeping in mind what Brad said (this appears to be server-side functionality), You can use this php code, but you should verify first that the uploaded file really is an image.
list($w, $h) = getimagesize($_FILES['yourUploadedFieldName']);
// $w holds the numeric width
// $h holds the numeric height
Upvotes: 4