Show More
@@ -637,7 +637,7 b' class Image(DisplayObject):' | |||||
637 | _FMT_PNG = u'png' |
|
637 | _FMT_PNG = u'png' | |
638 | _ACCEPTABLE_EMBEDDINGS = [_FMT_JPEG, _FMT_PNG] |
|
638 | _ACCEPTABLE_EMBEDDINGS = [_FMT_JPEG, _FMT_PNG] | |
639 |
|
639 | |||
640 |
def __init__(self, data=None, url=None, filename=None, format= |
|
640 | def __init__(self, data=None, url=None, filename=None, format=None, | |
641 | embed=None, width=None, height=None, retina=False, |
|
641 | embed=None, width=None, height=None, retina=False, | |
642 | unconfined=False, metadata=None): |
|
642 | unconfined=False, metadata=None): | |
643 | """Create a PNG/JPEG image object given raw data. |
|
643 | """Create a PNG/JPEG image object given raw data. | |
@@ -714,17 +714,27 b' class Image(DisplayObject):' | |||||
714 | else: |
|
714 | else: | |
715 | ext = None |
|
715 | ext = None | |
716 |
|
716 | |||
717 |
if |
|
717 | if format is None: | |
718 |
f |
|
718 | if ext is not None: | |
719 | if ext == u'jpg' or ext == u'jpeg': |
|
719 | if ext == u'jpg' or ext == u'jpeg': | |
720 | format = self._FMT_JPEG |
|
720 | format = self._FMT_JPEG | |
721 | if ext == u'png': |
|
721 | if ext == u'png': | |
722 | format = self._FMT_PNG |
|
722 | format = self._FMT_PNG | |
723 | elif isinstance(data, bytes) and format == 'png': |
|
723 | else: | |
724 | # infer image type from image data header, |
|
724 | format = ext.lower() | |
725 | # only if format might not have been specified. |
|
725 | elif isinstance(data, bytes): | |
726 | if data[:2] == _JPEG: |
|
726 | # infer image type from image data header, | |
727 | format = 'jpeg' |
|
727 | # only if format has not been specified. | |
|
728 | if data[:2] == _JPEG: | |||
|
729 | format = self._FMT_JPEG | |||
|
730 | ||||
|
731 | if format.lower() == 'jpg': | |||
|
732 | # jpg->jpeg | |||
|
733 | format = self._FMT_JPEG | |||
|
734 | ||||
|
735 | # failed to detect format, default png | |||
|
736 | if format is None: | |||
|
737 | format = 'png' | |||
728 |
|
738 | |||
729 | self.format = unicode_type(format).lower() |
|
739 | self.format = unicode_type(format).lower() | |
730 | self.embed = embed if embed is not None else (url is None) |
|
740 | self.embed = embed if embed is not None else (url is None) |
General Comments 0
You need to be logged in to leave comments.
Login now