whirlpool6 Posted August 21, 2007 Share Posted August 21, 2007 hello everyone, i am using javascript and php in my web application. before i display images, i would like to get their width and height. i used the getimagesize() function of php, but there are time when the width and height returned are blanks. i dont know how and i dont know why but there are really times like this. because of this, i started to search for a workaround when this scenario happens. i placed an onload function in my img tag. in that function i used this.width and this.height to get the size. but then, they returned zeroes. i dont know what to do now. can anybody please help me? how do i get the image width and height using either php or javascript? thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/65955-how-to-get-image-width-and-height/ Share on other sites More sharing options...
ToonMariner Posted August 21, 2007 Share Posted August 21, 2007 if getimagesize is returning null values then the path is incorrect or there is something wrong with the image file itself... Quote Link to comment https://forums.phpfreaks.com/topic/65955-how-to-get-image-width-and-height/#findComment-329752 Share on other sites More sharing options...
pranav_kavi Posted August 21, 2007 Share Posted August 21, 2007 Read this snippet frm http://www.php.net Note: Some formats may contain no image or may contain multiple images. In these cases, getimagesize() might not be able to properly determine the image size. getimagesize() will return zero for width and height in these cases. Quote Link to comment https://forums.phpfreaks.com/topic/65955-how-to-get-image-width-and-height/#findComment-329756 Share on other sites More sharing options...
MadTechie Posted August 21, 2007 Share Posted August 21, 2007 try this $image = "image.jpg"; if(file_exists($image)) { list($width , $height) = getimagesize($image); echo "w:$width, h:$height"; }else{ echo "file not found"; } Quote Link to comment https://forums.phpfreaks.com/topic/65955-how-to-get-image-width-and-height/#findComment-329757 Share on other sites More sharing options...
whirlpool6 Posted August 21, 2007 Author Share Posted August 21, 2007 there is really nothing wrong with the url... images still display in the end. this means that the image exists... but i have no idea why this returns blanks. im guessing that this may be because of slow download speed. i dont know... Quote Link to comment https://forums.phpfreaks.com/topic/65955-how-to-get-image-width-and-height/#findComment-329759 Share on other sites More sharing options...
MadTechie Posted August 21, 2007 Share Posted August 21, 2007 there is really nothing wrong with the url... images still display in the end. this means that the image exists... erm ok <?php $image = "http://#############.net/../#######/CSS/logo.png"; echo "<img src='$image' />"; //displays list($width , $height) = getimagesize($image); //fails echo "w:$width, h:$height"; ?> EDIT: removing the "/.." fixed it as the path was invalid to PHP but corrected by the browser Quote Link to comment https://forums.phpfreaks.com/topic/65955-how-to-get-image-width-and-height/#findComment-329764 Share on other sites More sharing options...
whirlpool6 Posted August 22, 2007 Author Share Posted August 22, 2007 madtechie thanks for the reply. so you mean that the url might be incorrect because of things like /..? what other things are not allowed? i mean, our url doesn't even have things like this. are there other things not allowed? and how does the browser correct such things? Quote Link to comment https://forums.phpfreaks.com/topic/65955-how-to-get-image-width-and-height/#findComment-330471 Share on other sites More sharing options...
whirlpool6 Posted August 22, 2007 Author Share Posted August 22, 2007 here is a sample of the image url used... HTTP://AAAAA/BBB/DOCUMENTUM//430/SS010/HL/2007/03/28/HL000000681360-1//NEW/ss010-2007032879383.jpg i dont know if anything is wrong here... Quote Link to comment https://forums.phpfreaks.com/topic/65955-how-to-get-image-width-and-height/#findComment-330544 Share on other sites More sharing options...
whirlpool6 Posted August 24, 2007 Author Share Posted August 24, 2007 hello guys, can anybody solve this? thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/65955-how-to-get-image-width-and-height/#findComment-332733 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.