2

Say I have the URL of an image, is there an easy way to get it's height/width using PHP? I'd prefer not to use javascript if possible.

1 Answer 1

7

You could use getimagesize

The getimagesize() function will determine the size of any given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML tag and the correspondant HTTP content type.

Returns an array with 7 elements.

Index 0 and 1 contains respectively the width and the height of the image.

list($width, $height, $type, $attr) = getimagesize("yourimage.jpg");

Also there is imagesx and imagesy functions to get width and height of images individually.

Sign up to request clarification or add additional context in comments.

2 Comments

Followup question (or should I ask a seperate question?) If URL file-access is disabled in the server configuration, and that's not something I can (or want) to change, do I have any options?
Could you open new question? So you could get more answer from many people.

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.