scardine / image_size

Get image width and height given a file path using minimal dependencies (no need for PIL, libjpeg, libpng, etc)
MIT License
153 stars 45 forks source link

TypeError: startswith first arg must be bytes or a tuple of bytes, not str #7

Closed KeithTurkowski closed 8 years ago

KeithTurkowski commented 8 years ago

I'm using python-3.5.1 and I get this error when trying to use your module.

Traceback (most recent call last):
File "C:\Users\Keith\Desktop\generate content\generate content.py", line 4, in <module>
width, height = get_image_size.get_image_size('x.jpg')
File "C:\Users\Keith\Desktop\generate content\get_image_size.py", line 71, in get_image_size
img = get_image_metadata(file_path)
File "C:\Users\Keith\Desktop\generate content\get_image_size.py", line 101, in get_image_metadata
elif ((size >= 24) and data.startswith('\211PNG\r\n\032\n')
TypeError: startswith first arg must be bytes or a tuple of bytes, not str`

I was able to resolve the issue by inserting a 'b' before the string in all of the 'startswith' calls.

e.g. data.startswith(b'\211PNG\r\n\032\n')

scardine commented 8 years ago

Thanks for reporting this bug.

I hope it is fixed now, let me know if you find any problem.

KeithTurkowski commented 8 years ago

Seems to be good, thanks!