def createDataConsumerFromPathName(path): # Create a CFURL for the supplied file system path. url = Cocoa.CFURLCreateWithFileSystemPath (None, path, Cocoa.kCFURLPOSIXPathStyle, False) if url is None: print("Couldn't create url!") return None # Create a Quartz data provider for the URL. dataConsumer = Quartz.CGDataConsumerCreateWithURL(url) if dataConsumer is None: print("Couldn't create data consumer!") return None return dataConsumer
def isImageFile_(self, filePath): isImageFile = False uti = None url = Cocoa.CFURLCreateWithFileSystemPath(None, filePath, Cocoa.kCFURLPOSIXPathStyle, False) res, info = LaunchServices.LSCopyItemInfoForURL( url, LaunchServices.kLSRequestExtension | LaunchServices.kLSRequestTypeCreator, None, ) if res == 0: # Obtain the UTI using the file information. # If there is a file extension, get the UTI. if info[3] != None: uti = LaunchServices.UTTypeCreatePreferredIdentifierForTag( LaunchServices.kUTTagClassFilenameExtension, info[3], LaunchServices.kUTTypeData, ) # No UTI yet if uti is None: # If there is an OSType, get the UTI. typeString = LaunchServices.UTCreateStringForOSType( info.filetype) if typeString != None: uti = LaunchServices.UTTypeCreatePreferredIdentifierForTag( LaunchServices.kUTTagClassOSType, typeString, LaunchServices.kUTTypeData, ) # Verify that this is a file that the ImageIO framework supports. if uti is not None: supportedTypes = Quartz.CGImageSourceCopyTypeIdentifiers() for item in supportedTypes: if LaunchServices.UTTypeConformsTo(uti, item): isImageFile = True break return isImageFile