当前位置: 首页>>代码示例>>Python>>正文


Python Image.from_file方法代码示例

本文整理汇总了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)
开发者ID:mwoinoski,项目名称:crs1906,代码行数:16,代码来源:imagescale-s.py

示例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)
开发者ID:mwoinoski,项目名称:crs1906,代码行数:17,代码来源:imagescale-q-m.py

示例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)
开发者ID:mwoinoski,项目名称:crs1906,代码行数:23,代码来源:imagescale-m.py


注:本文中的Image.Image.from_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。