Jump to content

how to get image width and height


whirlpool6

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.