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