def saveWithOptions(img, output, extension, extraInfo=None): """ @summary: Gets a dictionary with options for extension. @param img: PIL.Image to save. @param output: outfile where store img @param extension: Extension of the output file. """ try: if (extension == "JPEG"): img.save(output, extension, quality=jpegOptions["quality"]) if (extraInfo != None): __log__.debug("It is a JPEG image. It will set EXIF information...") ImageUtils.setJpegInfo(output, extraInfo) else: img.save(output, extension) except Exception, e: __log__.error("It could not save %s. %s" (output, e))
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: