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


Python Image.flip方法代码示例

本文整理汇总了Python中pgmagick.Image.flip方法的典型用法代码示例。如果您正苦于以下问题:Python Image.flip方法的具体用法?Python Image.flip怎么用?Python Image.flip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pgmagick.Image的用法示例。


在下文中一共展示了Image.flip方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_image

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import flip [as 别名]
    def get_image(self, source):
        blob = Blob()
        blob.update(source.read())
        image = Image(blob)
        orientation = image.orientation()

        if orientation in (OrientationType.UndefinedOrientation,
            OrientationType.TopLeftOrientation):
            pass
        elif orientation == OrientationType.TopRightOrientation:
            image.flop()
        elif orientation == OrientationType.BottomRightOrientation:
            image.rotate(180.)
        elif orientation == OrientationType.BottomLeftOrientation:
            image.flip()
        elif orientation == OrientationType.LeftTopOrientation:
            image.rotate(90.).flip()
        elif orientation == OrientationType.RightTopOrientation:
            image.rotate(90.)
        elif orientation == OrientationType.RightBottomOrientation:
            image.rotate(90.).flop()
        elif orientation == OrientationType.LeftBottomOrientation:
            image.rotate(270.)

        image.orientation(OrientationType.TopLeftOrientation)

        return image
开发者ID:vad,项目名称:sorl-thumbnail,代码行数:29,代码来源:pgmagick_engine.py

示例2: load_image

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import flip [as 别名]
def load_image(file, path):
    print "Loading image %s..." % file,

    try:
        file = open(path, 'rb')
    except IOError:
        print 'exists not'
        raise ValueError('Texture exists not')
    type, width, height = image_info(file.read(65536))
    file.seek(0, 0)
    if type:
        check_size(width, height)

    if magick:
        file.close()
        file = Image(path.encode('mbcs' if os.name == 'nt' else 'utf8'))
        geo = file.size()
        check_size(geo.width(), geo.height())
        print
        blob = Blob()
        file.flip()
        file.write(blob, 'RGBA')
        texture = blob.data
        mode = GL_RGBA
    else:
        try:
            raw = image.load(path, file=file)
        except IOError:
            print 'exists not'
            raise ValueError('Texture exists not')

        width, height = raw.width, raw.height
        check_size(width, height)
        print

        mode = GL_RGBA if 'A' in raw.format else GL_RGB
        # Flip from BGR to RGB
        if raw.format in ('BGR', 'BGRA'):
            if bgra:
                mode = {GL_RGBA: GL_BGRA, GL_RGB: GL_BGR}[mode]
                texture = raw.data
            else:
                texture = bgr_to_rgb(raw.data, width, height, 'A' in raw.format)
        elif raw.format in ('RGB', 'RGBA'):
            texture = raw.data
        else:
            texture = raw.get_data('RGBA', width * 4)
    return path, width, height, len(raw.format), mode, texture
开发者ID:,项目名称:,代码行数:50,代码来源:

示例3: load_texture

# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import flip [as 别名]
def load_texture(file):
    if file in cache:
        return cache[file]
    print "Loading image %s..." % file,

    path = os.path.join(os.path.dirname(__file__), "assets", "textures", file)

    try:
        file = open(path, 'rb')
    except IOError:
        print 'exists not'
        raise ValueError('Texture exists not')
    type, width, height = image_info(file.read(8192))
    file.seek(0, 0)
    if type:
        check_size(width, height)

    if magick:
        file.close()
        file = Image(path.encode('mbcs' if os.name == 'nt' else 'utf8'))
        geo = file.size()
        check_size(geo.width(), geo.height())
        print
        blob = Blob()
        file.flip()
        file.write(blob, 'RGBA')
        texture = blob.data
        mode = GL_RGBA
    else:
        try:
            raw = image.load(path, file=file)
        except IOError:
            print 'exists not'
            raise ValueError('Texture exists not')

        width, height = raw.width, raw.height
        check_size(width, height)
        print

        mode = GL_RGBA if 'A' in raw.format else GL_RGB
        # Flip from BGR to RGB
        # I hate you too, Pyglet...
        # REGULAR EXPRESSIONS ARE NOT MEANT TO PARSE BINARY DATA!!!
        #texture = raw.get_data('RGBA', width * 4) if safe else raw.data[::-1] if 'BGR' in raw.format else raw.data
        if raw.format in ('BGR', 'BGRA'):
            texture = bgr_to_rgb(raw.data, width, height, 'A' in raw.format)
        elif raw.format in ('RGB', 'RGBA'):
            texture = raw.data
        else:
            texture = raw.get_data('RGBA', width * 4)

    buffer = c_ulong()
    glGenTextures(1, byref(buffer))
    id = buffer.value

    glBindTexture(GL_TEXTURE_2D, id)

    filter = GL_NEAREST if badcard else GL_LINEAR
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter)
    glTexImage2D(GL_TEXTURE_2D, 0, mode, width, height, 0, mode, GL_UNSIGNED_BYTE, texture)

    cache[file] = id

    return id
开发者ID:quantum5,项目名称:SpaceTorus,代码行数:67,代码来源:texture.py


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