def findImageFile(filename):
 isfile = os.path.isfile
 if isfile(filename):
  return filename
 orig = copy.copy(filename)
 extensions = ('.jpg', '.png', '.tif', '.bmp', '.gif', '.jpeg', '.tiff')
 def logCorrected(orig, actual):
  logging.warn('Requested image {!r} not found but similar filename {!r} exists. This will be used instead but changing the filename is advised.'.format(orig, actual))
 if filename.endswith(extensions):
  filename = os.path.splitext(orig)[0]
 if isfile(filename):
  logCorrected(orig, filename)
  return filename
 for ext in extensions:
  if isfile((filename + ext)):
   filename += ext
   logCorrected(orig, filename)
   return filename

def findImageFile ( filename ) : isfile = os . path . isfile if isfile ( filename ) : return filename orig = copy . copy ( filename ) extensions = ( '.jpg' , '.png' , '.tif' , '.bmp' , '.gif' , '.jpeg' , '.tiff' ) def logCorrected ( orig , actual ) : logging . warn ( 'Requested image {!r} not found but similar filename {!r} exists. This will be used instead but changing the filename is advised.' . format ( orig , actual ) ) if filename . endswith ( extensions ) : filename = os . path . splitext ( orig ) [ 0 ] if isfile ( filename ) : logCorrected ( orig , filename ) return filename for ext in extensions : if isfile ( ( filename + ext ) ) : filename += ext logCorrected ( orig , filename ) return filename
tests whether the filename is an image file .