def openWithExtraInfo(path, extension): """ @summary: Gets a pointer and extra info from path. @param path: Path of image. @param extension: Extension of image. @return: Tuple within (handler of image, extraInfo) """ extraInfo = None try: img2do = Image.open(path) except IOError: __log__.error("An error has occurred when it was trying to open %s. Skip operation." % fileop) img2do = None if (extension == "JPEG"): extraInfo = ImageUtils.getJpegInfo(path) return (img2do, extraInfo)
def doOnPath(self, path): """ @summary: Do operation on path. @param path: File on path will be used as input file. @note: Generic operation will always do nothing. Its child classes should overwrite this method. """ # Open image to do operations over image object try: img2do = Image.open(path) except IOError: __log__.error("An error has occurred when it was trying to open %s. Skip operation." % path) img2do = None if (img2do != None): # HACKME: Try to remove dependency with jpeg infoExif = None infoExif2 = None infoComments = None infoExif, infoExif2, infoComments = ImageUtils.getJpegInfo(path) self.do(img2do) try: ext = string.lower(os.path.splitext(path)[1]) ext = Image.EXTENSION[ext] CamFormatOptions.saveWithOptions(img2do, path, ext) if (ext == "JPEG"): __log__.debug("It is a JPEG image. It will set EXIF information...") ImageUtils.setJpegInfo(path, (infoExif, infoExif2, infoComments)) except IOError, ioe: __log__.error("It could not save %s. Please check your permissions. %s" % (path, ioe)) raise IOError("It could not save %s. Please check your permissions. %s" % (path, ioe)) finally: