parameters: (imgname, imgdata=None)
return_statement: return width, height
docstring: Determine the image type of imgname (or imgdata) and return its size.
  
      Originally,
      Determine the image type of fhandle and return its size.
      from draco
docstring_summary: Determine the image type of imgname (or imgdata) and return its size.
docstring_tokens: Determine the image type of imgname ( or imgdata ) and return its size .
function: def get_image_size(imgname, imgdata=None):
      '''Determine the image type of imgname (or imgdata) and return its size.
  
      Originally,
      Determine the image type of fhandle and return its size.
      from draco'''
      if imgdata is None:
          fhandle = open(pathof(imgname), 'rb')
          head = fhandle.read(24)
      else:
          head = imgdata[0:24]
      if len(head) != 24:
          return
  
      imgtype = get_image_type(imgname, imgdata)
      if imgtype == 'png':
          check = struct.unpack(b'>i', head[4:8])[0]
          if check != 0x0d0a1a0a:
              return
          width, height = struct.unpack(b'>ii', head[16:24])
      elif imgtype == 'gif':
          width, height = struct.unpack(b'<HH', head[6:10])
      elif imgtype == 'jpeg' and imgdata is None:
          try:
              fhandle.seek(0)  # Read 0xff next
              size = 2
              ftype = 0
              while not 0xc0 <= ftype <= 0xcf:
                  fhandle.seek(size, 1)
                  byte = fhandle.read(1)
                  while ord(byte) == 0xff:
                      byte = fhandle.read(1)
                  ftype = ord(byte)
                  size = struct.unpack(b'>H', fhandle.read(2))[0] - 2
              # We are at a SOFn block
              fhandle.seek(1, 1)  # Skip `precision' byte.
              height, width = struct.unpack(b'>HH', fhandle.read(4))
          except Exception:  # IGNORE:W0703
              return
      elif imgtype == 'jpeg' and imgdata is not None:
          try:
              pos = 0
              size = 2
              ftype = 0
              while not 0xc0 <= ftype <= 0xcf:
                  pos += size
                  byte = imgdata[pos:pos+1]
                  pos += 1
                  while ord(byte) == 0xff:
                      byte = imgdata[pos:pos+1]
                      pos += 1
                  ftype = ord(byte)
                  size = struct.unpack(b'>H', imgdata[pos:pos+2])[0] - 2
                  pos += 2
              # We are at a SOFn block
              pos += 1  # Skip `precision' byte.
              height, width = struct.unpack(b'>HH', imgdata[pos:pos+4])
              pos += 4
          except Exception:  # IGNORE:W0703
              return
      else:
          return
      return width, height
function_tokens: def get_image_size ( imgname , imgdata = None ) : if imgdata is None : fhandle = open ( pathof ( imgname ) , 'rb' ) head = fhandle . read ( 24 ) else : head = imgdata [ 0 : 24 ] if len ( head ) != 24 : return imgtype = get_image_type ( imgname , imgdata ) if imgtype == 'png' : check = struct . unpack ( b'>i' , head [ 4 : 8 ] ) [ 0 ] if check != 0x0d0a1a0a : return width , height = struct . unpack ( b'>ii' , head [ 16 : 24 ] ) elif imgtype == 'gif' : width , height = struct . unpack ( b'<HH' , head [ 6 : 10 ] ) elif imgtype == 'jpeg' and imgdata is None : try : fhandle . seek ( 0 ) # Read 0xff next size = 2 ftype = 0 while not 0xc0 <= ftype <= 0xcf : fhandle . seek ( size , 1 ) byte = fhandle . read ( 1 ) while ord ( byte ) == 0xff : byte = fhandle . read ( 1 ) ftype = ord ( byte ) size = struct . unpack ( b'>H' , fhandle . read ( 2 ) ) [ 0 ] - 2 # We are at a SOFn block fhandle . seek ( 1 , 1 ) # Skip `precision' byte. height , width = struct . unpack ( b'>HH' , fhandle . read ( 4 ) ) except Exception : # IGNORE:W0703 return elif imgtype == 'jpeg' and imgdata is not None : try : pos = 0 size = 2 ftype = 0 while not 0xc0 <= ftype <= 0xcf : pos += size byte = imgdata [ pos : pos + 1 ] pos += 1 while ord ( byte ) == 0xff : byte = imgdata [ pos : pos + 1 ] pos += 1 ftype = ord ( byte ) size = struct . unpack ( b'>H' , imgdata [ pos : pos + 2 ] ) [ 0 ] - 2 pos += 2 # We are at a SOFn block pos += 1 # Skip `precision' byte. height , width = struct . unpack ( b'>HH' , imgdata [ pos : pos + 4 ] ) pos += 4 except Exception : # IGNORE:W0703 return else : return return width , height