1

^ As above. Is this possible?

I'm using a library to get image data from an mp3 and it returns the data as a byte string but to display the image I need to get the resolution and color depth.

Ideally I would prefer a library written in Python without dependencies so as to make my app as portable as possible.

If it's not too much trouble I would appreciate an example with the answer, thanks.

3
  • What library are you using? Does it not document the format it returns the image data in? Commented Jun 2, 2011 at 22:51
  • "it returns the data as a byte string" Commented Jun 2, 2011 at 23:20
  • Skimming the googles, it looks like image data will normally be either JPG or PNG, so zeekay's suggestion of using PIL is probably the best way to go. Is there a content-type field associated with the image data? Commented Jun 2, 2011 at 23:27

2 Answers 2

5

You can use PIL to work with images in Python. In your case you can do:

>>> from StringIO import StringIO
>>> from PIL import Image

>>> im = Image.open(StringIO(image_string))

>>> im.size, im.bits
<<< ((1654, 1279), 8)
Sign up to request clarification or add additional context in comments.

Comments

0

Either the image has headers (which you could read with something like exiftool), or the image does not have headers, in which case you can get the size and color depth from the specification, either of the container tag for mp3, or from the standard for the graphic.

Most bitmaps nowadays are 24bit color.

Comments

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.