Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.io.image
Commits
626b22ae
Commit
626b22ae
authored
Jul 27, 2016
by
Manuel Günther
Browse files
Hot-fixed weired imghdr issue with identfying jpegs
parent
c3c2c9e9
Changes
1
Hide whitespace changes
Inline
Side-by-side
bob/io/image/__init__.py
View file @
626b22ae
...
...
@@ -17,6 +17,12 @@ def get_config():
import
bob.extension
return
bob
.
extension
.
get_config
(
__name__
,
version
.
externals
)
# fix imghdr's jpeg detection to use the first two bytes (according to https://en.wikipedia.org/wiki/List_of_file_signatures)
import
imghdr
def
_test_jpeg
(
h
,
f
):
if
h
.
startswith
(
'
\xff\xd8
'
):
return
"jpeg"
imghdr
.
tests
.
append
(
_test_jpeg
)
def
load
(
filename
,
extension
=
None
):
"""load(filename) -> image
...
...
@@ -48,8 +54,10 @@ def load(filename, extension=None):
f
=
bob
.
io
.
base
.
File
(
filename
,
'r'
)
else
:
if
extension
==
'auto'
:
import
imghdr
extension
=
"."
+
imghdr
.
what
(
filename
)
extension
=
imghdr
.
what
(
filename
)
if
extension
is
None
:
raise
IOError
(
"Could not detect the image type of file %s"
%
filename
)
extension
=
"."
+
extension
f
=
bob
.
io
.
base
.
File
(
filename
,
'r'
,
extension
)
return
f
.
read
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment