Python Image.FLIP_TOP_BOTTOM Examples

The following are 12 code examples of Image.FLIP_TOP_BOTTOM(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module Image , or try the search function .
Example #1
Source File: images_stub.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def _CorrectOrientation(self, image, orientation):
    """Use PIL to correct the image orientation based on its EXIF.

    See JEITA CP-3451 at http://www.exif.org/specifications.html,
    Exif 2.2, page 18.

    Args:
      image: source PIL.Image.Image object.
      orientation: integer in range (1,8) inclusive, corresponding the image
        orientation from EXIF.

    Returns:
      PIL.Image.Image with transforms performed on it. If no correction was
        done, it returns the input image.
    """


    if orientation == 2:
      image = image.transpose(Image.FLIP_LEFT_RIGHT)
    elif orientation == 3:
      image = image.rotate(180)
    elif orientation == 4:
      image = image.transpose(Image.FLIP_TOP_BOTTOM)
    elif orientation == 5:
      image = image.transpose(Image.FLIP_TOP_BOTTOM)
      image = image.rotate(270)
    elif orientation == 6:
      image = image.rotate(270)
    elif orientation == 7:
      image = image.transpose(Image.FLIP_LEFT_RIGHT)
      image = image.rotate(270)
    elif orientation == 8:
      image = image.rotate(90)

    return image 
Example #2
Source File: transforms.py    From Qualia2.0 with MIT License 5 votes vote down vote up
def __call__(self, img):
        '''
        Args:
            img (PIL Image): Image to be flipped.
        '''
        if random.random() < self.p:
            if isinstance(img, np.ndarray):
                return img[:,:,::-1,:]
            elif isinstance(img, Image.Image):
                return img.transpose(Image.FLIP_TOP_BOTTOM)
        return img 
Example #3
Source File: gl.py    From pizza with GNU General Public License v2.0 5 votes vote down vote up
def save(self,file=None):
    self.w.update()      # force image on screen to be current before saving it
        
    pstring = glReadPixels(0,0,self.xpixels,self.ypixels,
                           GL_RGBA,GL_UNSIGNED_BYTE)
    snapshot = Image.fromstring("RGBA",(self.xpixels,self.ypixels),pstring)
    snapshot = snapshot.transpose(Image.FLIP_TOP_BOTTOM)

    if not file: file = self.file
    snapshot.save(file + ".png")

  # -------------------------------------------------------------------- 
Example #4
Source File: ImageFont.py    From mxnet-lambda with Apache License 2.0 5 votes vote down vote up
def getmask2(self, text, mode="", fill=Image.core.fill):
        size, offset = self.font.getsize(text)
        im = fill("L", size, 0)
        self.font.render(text, im.id, mode=="1")
        return im, offset

##
# Wrapper that creates a transposed font from any existing font
# object.
#
# @param font A font object.
# @param orientation An optional orientation.  If given, this should
#     be one of Image.FLIP_LEFT_RIGHT, Image.FLIP_TOP_BOTTOM,
#     Image.ROTATE_90, Image.ROTATE_180, or Image.ROTATE_270. 
Example #5
Source File: ImageOps.py    From mxnet-lambda with Apache License 2.0 5 votes vote down vote up
def flip(image):
    "Flip image vertically"
    return image.transpose(Image.FLIP_TOP_BOTTOM)

##
# Convert the image to grayscale.
#
# @param image The image to convert.
# @return An image. 
Example #6
Source File: img_pil.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def save(filename, width, height, fmt, pixels, flipped=False):
        image = PILImage.fromstring(fmt.upper(), (width, height), pixels)
        if flipped:
            image = image.transpose(PILImage.FLIP_TOP_BOTTOM)
        image.save(filename)
        return True


# register 
Example #7
Source File: img_pil.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def save(filename, width, height, fmt, pixels, flipped=False):
        image = PILImage.fromstring(fmt.upper(), (width, height), pixels)
        if flipped:
            image = image.transpose(PILImage.FLIP_TOP_BOTTOM)
        image.save(filename)
        return True


# register 
Example #8
Source File: ImageFont.py    From CNCGToolKit with MIT License 5 votes vote down vote up
def getmask2(self, text, mode="", fill=Image.core.fill):
        size, offset = self.font.getsize(text)
        im = fill("L", size, 0)
        self.font.render(text, im.id, mode=="1")
        return im, offset

##
# Wrapper that creates a transposed font from any existing font
# object.
#
# @param font A font object.
# @param orientation An optional orientation.  If given, this should
#     be one of Image.FLIP_LEFT_RIGHT, Image.FLIP_TOP_BOTTOM,
#     Image.ROTATE_90, Image.ROTATE_180, or Image.ROTATE_270. 
Example #9
Source File: ImageOps.py    From CNCGToolKit with MIT License 5 votes vote down vote up
def flip(image):
    "Flip image vertically"
    return image.transpose(Image.FLIP_TOP_BOTTOM)

##
# Convert the image to grayscale.
#
# @param image The image to convert.
# @return An image. 
Example #10
Source File: ImageOps.py    From keras-lambda with MIT License 5 votes vote down vote up
def flip(image):
    "Flip image vertically"
    return image.transpose(Image.FLIP_TOP_BOTTOM)

##
# Convert the image to grayscale.
#
# @param image The image to convert.
# @return An image. 
Example #11
Source File: pil.py    From pyglet with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def decode(self, file, filename):
        try:
            image = Image.open(file)
        except Exception as e:
            raise ImageDecodeException(
                'PIL cannot read %r: %s' % (filename or file, e))

        try:
            image = image.transpose(Image.FLIP_TOP_BOTTOM)
        except Exception as e:
            raise ImageDecodeException('PIL failed to transpose %r: %s' % (filename or file, e))

        # Convert bitmap and palette images to component
        if image.mode in ('1', 'P'):
            image = image.convert()

        if image.mode not in ('L', 'LA', 'RGB', 'RGBA'):
            raise ImageDecodeException('Unsupported mode "%s"' % image.mode)
        width, height = image.size

        # tostring is deprecated, replaced by tobytes in Pillow (PIL fork)
        # (1.1.7) PIL still uses it
        image_data_fn = getattr(image, "tobytes", getattr(image, "tostring"))
        return ImageData(width, height, image.mode, image_data_fn())

    # def decode_animation(self, file, filename):
    #     try:
    #         image = Image.open(file)
    #     except Exception as e:
    #         raise ImageDecodeException('PIL cannot read %r: %s' % (filename or file, e))
    #
    #     frames = []
    #
    #     for image in ImageSequence.Iterator(image):
    #         try:
    #             image = image.transpose(Image.FLIP_TOP_BOTTOM)
    #         except Exception as e:
    #             raise ImageDecodeException('PIL failed to transpose %r: %s' % (filename or file, e))
    #
    #         # Convert bitmap and palette images to component
    #         if image.mode in ('1', 'P'):
    #             image = image.convert()
    #
    #         if image.mode not in ('L', 'LA', 'RGB', 'RGBA'):
    #             raise ImageDecodeException('Unsupported mode "%s"' % image.mode)
    #
    #         duration = None if image.info['duration'] == 0 else image.info['duration']
    #         # Follow Firefox/Mac behaviour: use 100ms delay for any delay less than 10ms.
    #         if duration <= 10:
    #             duration = 100
    #
    #         frames.append(AnimationFrame(ImageData(*image.size, image.mode, image.tobytes()), duration / 1000))
    #
    #     return Animation(frames) 
Example #12
Source File: ImageFont.py    From keras-lambda with MIT License 4 votes vote down vote up
def getmask2(self, text, mode="", fill=Image.core.fill):
        size, offset = self.font.getsize(text)
        im = fill("L", size, 0)
        self.font.render(text, im.id, mode=="1")
        return im, offset

##
# Wrapper that creates a transposed font from any existing font
# object.
#
# @param font A font object.
# @param orientation An optional orientation.  If given, this should
#     be one of Image.FLIP_LEFT_RIGHT, Image.FLIP_TOP_BOTTOM,
#     Image.ROTATE_90, Image.ROTATE_180, or Image.ROTATE_270.