本文整理汇总了Python中photo.Photo.autorotate方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.autorotate方法的具体用法?Python Photo.autorotate怎么用?Python Photo.autorotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类photo.Photo
的用法示例。
在下文中一共展示了Photo.autorotate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import autorotate [as 别名]
def start(self, rootDir):
""" Lance les calculs
@param rootDir: top level directory to start processing
@return: 2tuple containing the list of all images and the start-index
@rtype: (list,integer)
"""
config.DefaultRepository = rootDir
AllJpegs = fileutils.findFiles(rootDir)
AllFilesToProcess = []
AllreadyDone = []
NewFiles = []
uid = os.getuid()
gid = os.getgid()
for i in AllJpegs:
if i.find(config.TrashDirectory) == 0: continue
if i.find(config.SelectedDirectory) == 0: continue
try:
a = int(i[:4])
m = int(i[5:7])
j = int(i[8:10])
if (a >= 0000) and (m <= 12) and (j <= 31) and (i[4] in ["-", "_", "."]) and (i[7] in ["-", "_"]):
AllreadyDone.append(i)
else:
AllFilesToProcess.append(i)
except ValueError:
AllFilesToProcess.append(i)
AllFilesToProcess.sort()
NumFiles = len(AllFilesToProcess)
self.startSignal.emit(self.__label, NumFiles)
for h in range(NumFiles):
i = AllFilesToProcess[h]
self.refreshSignal.emit(h, i)
myPhoto = Photo(i, dontCache=True)
data = myPhoto.readExif()
try:
datei, heurei = data["Heure"].split()
date = re.sub(":", "-", datei)
heurej = re.sub(":", "h", heurei, 1)
model = data["Modele"].split(",")[-1]
heure = unicode2ascii("%s-%s.jpg" % (re.sub(":", "m", heurej, 1), re.sub("/", "", re.sub(" ", "_", model))))
except ValueError:
date = time.strftime("%Y-%m-%d", time.gmtime(os.path.getctime(os.path.join(rootDir, i))))
heure = unicode2ascii("%s-%s.jpg" % (time.strftime("%Hh%Mm%S", time.gmtime(os.path.getctime(os.path.join(rootDir, i)))), re.sub("/", "-", re.sub(" ", "_", os.path.splitext(i)[0]))))
if not (os.path.isdir(os.path.join(rootDir, date))) :
fileutils.mkdir(os.path.join(rootDir, date))
# strImageFile = os.path.join(rootDir, date, heure)
ToProcess = os.path.join(date, heure)
bSkipFile = False
for strImageFile in fileutils.list_files_in_named_dir(rootDir, date, heure):
logger.warning("%s -x-> %s", i, strImageFile)
existing = Photo(strImageFile, dontCache=True)
try:
existing.readExif()
originalName = existing.exif["Exif.Photo.UserComment"]
except:
logger.error("in ModelRangeTout: reading Exif for %s", i)
else:
if "human_value" in dir(originalName):
originalName = originalName.human_value
if os.path.basename(originalName) == os.path.basename(i):
logger.info("File already in repository, leaving as it is")
bSkipFile = True
continue #to next file, i.e. leave the existing one
if bSkipFile:
continue
else:
strImageFile = os.path.join(rootDir, date, heure)
if os.path.isfile(strImageFile):
s = 0
for j in os.listdir(os.path.join(rootDir, date)):
if j.find(heure[:-4]) == 0:s += 1
ToProcess = os.path.join(date, heure[:-4] + "-%s.jpg" % s)
strImageFile = os.path.join(rootDir, ToProcess)
shutil.move(os.path.join(rootDir, i), strImageFile)
try:
os.chown(strImageFile, uid, gid)
os.chmod(strImageFile, config.DefaultFileMode)
except OSError:
logger.warning("in ModelRangeTout: unable to chown ot chmod %s" , strImageFile)
myPhoto = Photo(strImageFile, dontCache=True)
# Save the old image name in exif tag
myPhoto.storeOriginalName(i)
if config.AutoRotate:
myPhoto.autorotate()
AllreadyDone.append(ToProcess)
NewFiles.append(ToProcess)
AllreadyDone.sort()
self.finishSignal.emit()
if len(NewFiles) > 0:
FirstImage = min(NewFiles)
return AllreadyDone, AllreadyDone.index(FirstImage)
else:
return AllreadyDone, 0