Example #1
0
def flip_image(img, flip):
    from calibre.utils.img import flip_image, image_and_format_from_data, image_to_data
    with lopen(img, 'r+b') as f:
        img, fmt = image_and_format_from_data(f.read())
        img = flip_image(img, horizontal='x' in flip, vertical='y' in flip)
        f.seek(0), f.truncate()
        f.write(image_to_data(img, fmt=fmt))
Example #2
0
def flip_image(img, flip):
    from calibre.utils.img import flip_image, image_and_format_from_data, image_to_data
    with lopen(img, 'r+b') as f:
        img, fmt = image_and_format_from_data(f.read())
        img = flip_image(img, horizontal='x' in flip, vertical='y' in flip)
        f.seek(0), f.truncate()
        f.write(image_to_data(img, fmt=fmt))
Example #3
0
 def convert_webp(self, item):
     from calibre.utils.img import image_and_format_from_data, image_to_data
     img, fmt = image_and_format_from_data(item.data)
     if fmt == 'webp' and not img.isNull():
         self.log.info(f'Converting WebP image {item.href} to PNG')
         item.data = image_to_data(img, fmt='PNG')
         item.media_type = 'image/png'
Example #4
0
 def __init__(self, path_or_bytes):
     if not isinstance(path_or_bytes, bytes):
         with open(path_or_bytes, 'rb') as f:
             path_or_bytes = f.read()
     self.img_data = path_or_bytes
     fmt, width, height = identify(path_or_bytes)
     self.img, self.fmt = image_and_format_from_data(path_or_bytes)
     self.width, self.height = self.img.width(), self.img.height()
     self.cache_key = self.img.cacheKey()
Example #5
0
 def load(self, data):
     if not data:
         raise ValueError('No image data present')
     self.img, self.read_format = image_and_format_from_data(data)
Example #6
0
 def load(self, data):
     if not data:
         raise ValueError('No image data present')
     self.img, self.read_format = image_and_format_from_data(data)
Example #7
0
 def identify(self, data):
     img, fmt = image_and_format_from_data(data)
     return img.width(), img.height(), fmt
Example #8
0
 def load(self, data):
     if not data:
         raise ValueError('Cannot open image from empty data string')
     img, self.read_format = image_and_format_from_data(data)
     self.from_qimage(img)