def __init__(self, window: MainWindow): super().__init__(title='About') self.__window = window self.set_modal(True) self.set_transient_for(self.__window) self.set_titlebar(Gtk.HeaderBar(title='About')) logo = Path(__file__).parent / 'images' / 'mcomix.png' self.set_logo(ImageTools.pil_to_pixbuf(Image.open(logo))) self.set_name(Mcomix.APP_NAME.value) self.set_program_name(Mcomix.APP_NAME.value) self.set_version(f'Version {Mcomix.VERSION.value}') self.set_copyright('Copyright (C) 2005-2021') self.set_license_type(Gtk.License.GPL_2_0) link = f'https://github.com/thermitegod/{Mcomix.PROG_NAME.value}' self.set_website(link) self.set_website_label(link) self.set_comments(f'{Mcomix.APP_NAME.value} is an image viewer specifically designed ' f'to handle manga, comics, and image files.') self.show_all()
def draw_histogram(self, height: int = 170, fill: int = 170): """ Draw a histogram (RGB) from self.__pixbuf and return it as another pixbuf. :param height: height of the returned pixbuf :param fill: determines the color intensity of the filled graphs, valid values are between 0 and 255. :returns: modified pixbuf, the returned prixbuf will be 262x<height> px. """ self.__pixbuf = ImageTools.static_image(self.__pixbuf) im = Image.new('RGB', (258, height - 4), (30, 30, 30)) hist_data = ImageTools.pixbuf_to_pil(self.__pixbuf).histogram() maximum = max(hist_data[:768] + [1]) y_scale = (height - 6) / maximum r = [int(hist_data[n] * y_scale) for n in range(256)] g = [int(hist_data[n] * y_scale) for n in range(256, 512)] b = [int(hist_data[n] * y_scale) for n in range(512, 768)] im_data = im.getdata() # Draw the filling colors for x in range(256): for y in range(1, max(r[x], g[x], b[x]) + 1): r_px = fill if y <= r[x] else 0 g_px = fill if y <= g[x] else 0 b_px = fill if y <= b[x] else 0 im_data.putpixel((x + 1, height - 5 - y), (r_px, g_px, b_px)) # Draw the outlines for x in range(1, 256): self._im_putpixel(x=x, channel=r, height=height, im_data=im_data) self._im_putpixel(x=x, channel=g, height=height, im_data=im_data) self._im_putpixel(x=x, channel=b, height=height, im_data=im_data) if config['ENHANCE_EXTRA']: # if True a label with the maximum pixel value will be added to one corner maxstr = f'max pixel value: {maximum}' draw = ImageDraw.Draw(im) draw.rectangle((0, 0, len(maxstr) * 6 + 2, 10), fill=(30, 30, 30)) draw.text((2, 0), maxstr, fill=(255, 255, 255)) im = ImageOps.expand(im, 1, (80, 80, 80)) im = ImageOps.expand(im, 1, (0, 0, 0)) self.__hist_image.set_from_pixbuf(ImageTools.pil_to_pixbuf(im))
def __call__(self, size: tuple, filepath: Path): """ Returns a thumbnail pixbuf for <filepath>, transparently handling both normal image files and archives. Returns None if thumbnail creation failed, or if the thumbnail creation is run asynchrounosly :param size: The dimensions for the created thumbnails (width, height). :param filepath: Path to the image that the thumbnail is generated from. """ try: with LockedFileIO(filepath) as fio: with Image.open(fio) as im: im.thumbnail(size, resample=Image.BOX) pixbuf = ImageTools.pil_to_pixbuf(im) if ImageTools.pil_has_alpha(im): pixbuf = ImageTools.add_alpha_background(pixbuf, pixbuf.get_width(), pixbuf.get_height()) except Exception as ex: logger.error(f'Failed to create thumbnail for image: \'{filepath}\'') logger.error(f'Exception: {ex}') pixbuf = None return pixbuf