コード例 #1
0
    def transpose(self):
        """ Transpose the image (across  upper-right -> lower-left axis)

        :return:        transposed image
        :rtype:         jpegtran.JPEGImage

        """
        new = JPEGImage(blob=lib.Transformation(self.data).transpose())
        new._update_thumbnail()
        return new
コード例 #2
0
    def flip(self, direction):
        """ Flip the image in horizontal or vertical direction.

        :param direction: Flipping direction
        :type direction:  'vertical' or 'horizontal'
        :return:        flipped image
        :rtype:         jpegtran.JPEGImage

        """
        if direction not in ('horizontal', 'vertical'):
            raise ValueError("Direction must be either 'vertical' or "
                             "'horizontal'")
        new = JPEGImage(blob=lib.Transformation(self.data).flip(direction))
        new._update_thumbnail()
        return new
コード例 #3
0
    def rotate(self, angle):
        """ Rotate the image.

        :param angle:   rotation angle
        :type angle:    -90, 90, 180 or 270
        :return:        rotated image
        :rtype:         jpegtran.JPEGImage

        """
        if angle not in (-90, 90, 180, 270):
            raise ValueError("Angle must be -90, 90, 180 or 270.")
        img = JPEGImage(blob=lib.Transformation(self.data).rotate(angle))
        # Set EXIF orientation to 'Normal' (== no rotation)
        if img.exif_orientation not in (None, 1):
            img.exif_orientation = 1
        img._update_thumbnail()
        return img
コード例 #4
0
    def downscale(self, width, height, quality=75):
        """ Downscale the image.

        :param width:   Scaled image width
        :type width:    int
        :param height:  Scaled image height
        :type height:   int
        :param quality: JPEG quality of scaled image (default: 75)
        :type quality:  int
        :return:        downscaled image
        :rtype:         jpegtran.JPEGImage

        """
        if width == self.width and height == self.height:
            return self
        if width > self.width or height > self.height:
            raise ValueError("jpegtran can only downscale JPEGs")
        new = JPEGImage(blob=lib.Transformation(self.data)
                        .scale(width, height, quality))
        new._update_thumbnail()
        return new
コード例 #5
0
    def crop(self, x, y, width, height):
        """ Crop a rectangular area from the image.

        :param x:       horizontal coordinate of upper-left corner
        :type x:        int
        :param y:       vertical coordinate of upper-left corner
        :type y:        int
        :param width:   width of area
        :type width:    int
        :param height:  height of area
        :type height:   int
        :return:        cropped image
        :rtype:         jpegtran.JPEGImage

        """
        valid_crop = (x < self.width and y < self.height and
                      x+width <= self.width and y+height <= self.height)
        if not valid_crop:
            raise ValueError("Crop parameters point outside of the image")
        new = JPEGImage(blob=lib.Transformation(self.data)
                             .crop(x, y, width, height))
        new._update_thumbnail()
        return new
コード例 #6
0
 def height(self):
     """ Height of the image in pixels. """
     return lib.Transformation(self.data).get_dimensions()[1]
コード例 #7
0
 def width(self):
     """ Width of the image in pixels. """
     return lib.Transformation(self.data).get_dimensions()[0]