Ejemplo n.º 1
0
def open(path, fileName):
    """Opens and identifies the given image file. This is a lazy operation
        return an Image object
    """
    full = os.path.join(path, fileName)
    if not file_utils.isFileExist(full):
        raise Exception("path %s not exist" % full)
    
    return Image.open(full)
Ejemplo n.º 2
0
def _save(img, path, filename, format="JPEG", _quality=IMG_QUALITY, create_dir=True):
    '''save Image object to file system, according to the value of create_dir
    to create a new dir , or not
    
    params:
        create_dir:  if True, when then filepath not exists, create new one
            or not create.
    '''
    
    if not file_utils.isFileExist(path):
        if create_dir:
            os.makedirs(path)
            logger.info("path [%s] not exist, new one created" % path)
        else:
            logger.error("save file failed, path [%s] not exist" % path)
            return False    
    try:
        img.save(os.path.join(path, filename), format, quality=_quality)
        logger.debug("File with name %s saved" % filename)
        return True
    except:
        utils.traceBack()
        return False