##// END OF EJS Templates
Extract width and height from gif base64 string
Grant Nestor -
Show More
@@ -965,8 +965,7 b' def _pngxy(data):'
965 """read the (width, height) from a PNG header"""
965 """read the (width, height) from a PNG header"""
966 ihdr = data.index(b'IHDR')
966 ihdr = data.index(b'IHDR')
967 # next 8 bytes are width/height
967 # next 8 bytes are width/height
968 w4h4 = data[ihdr+4:ihdr+12]
968 return struct.unpack('>ii', data[ihdr+4:ihdr+12])
969 return struct.unpack('>ii', w4h4)
970
969
971 def _jpegxy(data):
970 def _jpegxy(data):
972 """read the (width, height) from a JPEG header"""
971 """read the (width, height) from a JPEG header"""
@@ -984,8 +983,11 b' def _jpegxy(data):'
984 # read another block
983 # read another block
985 idx += 2
984 idx += 2
986
985
987 h, w = struct.unpack('>HH', data[iSOF+5:iSOF+9])
986 return struct.unpack('>HH', data[iSOF+5:iSOF+9])
988 return w, h
987
988 def _gifxy(data):
989 """read the (width, height) from a GIF header"""
990 return struct.unpack('<HH', data[6:10])
989
991
990 class Image(DisplayObject):
992 class Image(DisplayObject):
991
993
@@ -1126,7 +1128,7 b' class Image(DisplayObject):'
1126 elif self.format == self._FMT_JPEG:
1128 elif self.format == self._FMT_JPEG:
1127 w, h = _jpegxy(self.data)
1129 w, h = _jpegxy(self.data)
1128 elif self.format == self._FMT_GIF:
1130 elif self.format == self._FMT_GIF:
1129 w, h = _pngxy(self.data)
1131 w, h = _gifxy(self.data)
1130 else:
1132 else:
1131 # retina only supports png
1133 # retina only supports png
1132 return
1134 return
General Comments 0
You need to be logged in to leave comments. Login now