本文整理汇总了Python中Image.Image.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Image.from_file方法的具体用法?Python Image.from_file怎么用?Python Image.from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image.Image
的用法示例。
在下文中一共展示了Image.from_file方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scale_one
# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import from_file [as 别名]
def scale_one(size, smooth, sourceImage, targetImage):
oldImage = Image.from_file(sourceImage)
if oldImage.width <= size and oldImage.height <= size:
oldImage.save(targetImage)
return Result(1, 0)
else:
if smooth:
scale = min(size / oldImage.width, size / oldImage.height)
newImage = oldImage.scale(scale)
else:
stride = int(math.ceil(max(oldImage.width / size, oldImage.height / size)))
newImage = oldImage.subsample(stride)
newImage.save(targetImage)
return Result(0, 1)
示例2: scale_one
# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import from_file [as 别名]
def scale_one(size, smooth, scr_image, dest_image):
old_image = Image.from_file(scr_image)
if old_image.width <= size and old_image.height <= size:
old_image.save(dest_image)
return Result(1, 0, dest_image)
else:
if smooth:
scale = min(size / old_image.width, size / old_image.height)
new_image = old_image.scale(scale)
else:
stride = int(math.ceil(max(old_image.width / size,
old_image.height / size)))
new_image = old_image.subsample(stride)
new_image.save(dest_image)
return Result(0, 1, dest_image)
示例3: scale_one
# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import from_file [as 别名]
def scale_one(size, smooth, sourceImage, targetImage):
try:
oldImage = Image.from_file(sourceImage)
if oldImage.width <= size and oldImage.height <= size:
oldImage.save(targetImage)
return Result(1, 0, targetImage)
else:
if smooth:
scale = min(size / oldImage.width, size / oldImage.height)
newImage = oldImage.scale(scale)
else:
stride = int(math.ceil(max(oldImage.width / size,
oldImage.height / size)))
newImage = oldImage.subsample(stride)
newImage.save(targetImage)
return Result(0, 1, targetImage)
except Exception as e:
Qtrac.report("Problem scaling " +
os.path.basename(sourceImage), error=True)
Qtrac.report(str(e), error=True)
return Result(0, 0, sourceImage)