0

How to get width and height of an image?

I have $variable = 'http://site.com/image.png"

Want to get width of this image to $width and height to $height.

Like: $variable = 'http://site.com/image.png"

$width = '300'; // image width is 300px
$height = '500'; // height is 500px

Thanks.

3

2 Answers 2

2
$variable = 'http://site.com/image.png';
$image    = getimagesize($variable);
$width    = $image[0];
$height   = $image[1];
$type     = $image[2];
Sign up to request clarification or add additional context in comments.

Comments

1

getimagesize function. Maybe it will help you.

2 Comments

Caveat: the combination of remote FS and image functions can have subtle quirks, e.g. if the remote HTTP server is slow to respond, execution will hang until getimagesize() returns (which can be "until HTTP connection times out", which means tens of seconds).
Certainly you want to cache the results of any image size check you do - if its at all possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.