1

Is there anyway to get image width and height without downloading from original location in PYTHON. I have an idea how to get image info when it is in our server. Buy no idea this can do with online resource image in PYTHON.

Finally done this as follow in python. Anyway have to download and get image info

import cStringIO
import urllib
import Image
file = urllib.urlopen('http://static.php.net/www.php.net/images/php.gif')
im = cStringIO.StringIO(file.read())
img = Image.open(im)
print img.format, img.size, img.mode
GIF (120, 67) P
width, height = img.size
print width, height
0

1 Answer 1

3

You can't. You must download a certain amount of the file before you get to the metadata that contains the dimensions of the image.

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

8 Comments

But in php we can do this as follow. why we can not do with python <?php $size = getimagesize("static.php.net/www.php.net/images/php.gif"); var_dump($size); ?>
Above code giving fallowing result array(7) { [0]=> int(120) [1]=> int(67) [2]=> int(1) [3]=> string(23) "width="120" height="67"" ["bits"]=> int(7) ["channels"]=> int(3) ["mime"]=> string(9) "image/gif" }
Do you really believe that PHP doesn't download part of the file when doing that?!
I have no idea what is happening in side the "getimagesize()" php lib function in php. It is giving width and height?
If you don't understand what it's doing then why are you presenting it as an example?
|

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.