File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -163,23 +163,27 @@ def _to_tcod_color(color):
163163
164164def _getImageSize (filename ):
165165 """Try to get the width and height of a bmp of png image file"""
166+ result = None
166167 file = open (filename , 'rb' )
167168 if file .read (8 ) == b'\x89 PNG\r \n \x1a \n ' : # PNG
168169 while 1 :
169170 length , = _struct .unpack ('>i' , file .read (4 ))
170171 chunkID = file .read (4 )
171172 if chunkID == '' : # EOF
172- return None
173+ break
173174 if chunkID == b'IHDR' :
174175 # return width, height
175- return _struct .unpack ('>ii' , file .read (8 ))
176+ result = _struct .unpack ('>ii' , file .read (8 ))
177+ break
176178 file .seek (4 + length , 1 )
179+ file .close ()
180+ return result
177181 file .seek (0 )
178182 if file .read (8 ) == b'BM' : # Bitmap
179183 file .seek (18 , 0 ) # skip to size data
180- # return width, height
181- return _struct . unpack ( '<ii' , file .read ( 8 ) )
182- # return None on error, unknown file
184+ result = _struct . unpack ( '<ii' , file . read ( 8 ))
185+ file .close ( )
186+ return result # (width, height), or None
183187
184188class TDLError (Exception ):
185189 """
You can’t perform that action at this time.
0 commit comments