def extractJPEG(self): """ extract the raw image to its right place """ extension = op.splitext(self.strRawFile)[1].lower() strJpegFullPath = op.join(config.DefaultRepository, self.getJpegPath()) if extension in config.RawExtensions: process = subprocess.Popen("%s %s" % (config.Dcraw, self.strRawFile), shell=True, stdout=subprocess.PIPE) ret = process.wait() if ret != 0: logger.error("'%s %s' ended with error %s" % (config.Dcraw, self.strRawFile, ret)) data = process.stdout.readlines() img = Image.fromstring("RGB", tuple([int(i) for i in data[1].split()]), "".join(tuple(data[3:]))) img.save(strJpegFullPath, format='JPEG') #Copy all metadata useful for us. exifJpeg = Exif(strJpegFullPath) exifJpeg.read() exifJpeg['Exif.Image.Orientation'] = 1 exifJpeg["Exif.Photo.UserComment"] = self.strRawFile for metadata in [ 'Exif.Image.Make', 'Exif.Image.Model', 'Exif.Photo.DateTimeOriginal', 'Exif.Photo.ExposureTime', 'Exif.Photo.FNumber', 'Exif.Photo.ExposureBiasValue', 'Exif.Photo.Flash', 'Exif.Photo.FocalLength', 'Exif.Photo.ISOSpeedRatings']: try: exifJpeg[metadata] = self.exif[metadata] except: logger.error("Unable to copying metadata %s in file %s, value: %s" % (metadata, self.strRawFile, self.exif[metadata])) #self.exif.copyMetadataTo(self.strJepgFile) exifJpeg.write() else: #in config.Extensions, i.e. a JPEG file shutil.copy(self.strRawFile, strJpegFullPath) Exiftran.autorotate(strJpegFullPath) os.chmod(strJpegFullPath, config.DefaultFileMode)
def autorotate(self): """does autorotate the image according to the EXIF tag""" if os.name == 'nt' and self.pil is not None: del self.pil self.readExif() if self.orientation != 1: Exiftran.autorotate(self.fn) if self.orientation > 4: self.pixelsX = self.exif["Exif.Photo.PixelYDimension"] self.pixelsY = self.exif["Exif.Photo.PixelXDimension"] self.metadata["Resolution"] = "%s x %s " % (self.pixelsX, self.pixelsY) self.orientation = 1