From 936c24fd79d885912de21af2cd38c8eee87a7c6f Mon Sep 17 00:00:00 2001 From: Markil 3 Date: Fri, 5 Dec 2025 08:46:00 -0700 Subject: [PATCH] Does some more work on the transformed version. --- pyproject.toml | 2 +- setup.cfg | 2 +- src/comic_download/dinosaur_comics.py | 46 +++++++++++++++------------ 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b547de3..e5dbc28 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "comic_download" -version = "0.1.0" +version = "0.2.0" authors = [ {name = "Markil 3", email = "markil3@singlepilot.net"} ] diff --git a/setup.cfg b/setup.cfg index 3aa61d6..a2aa6c6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = comic_download -version = 0.1.0 +version = 0.2.0 [options] package_dir= diff --git a/src/comic_download/dinosaur_comics.py b/src/comic_download/dinosaur_comics.py index a1f0b2e..9fead7b 100644 --- a/src/comic_download/dinosaur_comics.py +++ b/src/comic_download/dinosaur_comics.py @@ -24,6 +24,7 @@ import json import re from urllib.parse import urlparse, parse_qs +from importlib import resources from pathlib import Path from tempfile import NamedTemporaryFile @@ -49,7 +50,8 @@ class DinosaurComic(Comic): self.title = "Dinosaur Comics!" self.author = "Ryan North" self.image_urls = { - "header": "https://www.qwantz.com/logo5.png", + "header": "https://www.qwantz.com/logo.png", + "background": "https://www.qwantz.com/sky.png" } self.description = "this comic... might be the best comic?" @@ -64,7 +66,6 @@ class DinosaurComic(Comic): for archive_month in archives: link_el = archive_month.find("a") if link_el: - print(archive_month) parsed_index = urlparse(link_el["href"]) identifier = int(parse_qs(parsed_index.query)["comic"][0]) date_str = link_el.get_text() @@ -72,7 +73,7 @@ class DinosaurComic(Comic): self.strips.append({ "identifier": identifier, "date": date, - "description": link_el.next_sibling.get_text() + "description": link_el.next_sibling.get_text()[2:] }) self.strips.sort(key=lambda x: x["date"]) for i in range(len(self.strips)): @@ -145,28 +146,25 @@ class DinosaurComicStrip(ComicStrip): title_box = title_font.getbbox(self.title) title_box = (title_box[2] - title_box[0], title_box[3] - title_box[1]) - - description = textwrap.wrap(self.description, width=img.width // description_size) - description_lines = len(description) - description_box = description_font.getbbox(max(description, key=len)) - description_box = (description_box[2] - description_box[0], (description_box[3] - description_box[1] + description_spacing) * len(description)) - description = "\n".join(description) + caption_spacing = 4 url_box = caption_font.getbbox(self.url) url_box = (url_box[2] - url_box[0], url_box[3] - url_box[1]) date_box = caption_font.getbbox(self.date.isoformat()) date_box = (date_box[2] - date_box[0], date_box[3] - date_box[1]) - text_margin = 10 + text_margin = 20 self.transformed_images = [] header_img = Image.open(self.comic.images["header"].name) + background_img = Image.open(self.comic.images["background"].name) for i in range(len(self.images)): img = Image.open(self.images[i].name) + comic_width = max(img.width, header_img.width) if self.captions[i]: # Take measurements of the page caption, if one is present. # Pillow's bbox functions do not handle newline characters properly, so we have to # split the text, find the widest line, and use that. - caption = textwrap.wrap(self.captions[i], width = img.width // caption_size) + caption = textwrap.wrap(self.captions[i], width = comic_width // caption_size) caption_lines = len(caption) caption_box = caption_font.getbbox(max(caption, key=len)) caption_box = (caption_box[2] - caption_box[0], (caption_box[3] - caption_box[1] + caption_spacing) * len(caption)) @@ -175,32 +173,38 @@ class DinosaurComicStrip(ComicStrip): caption_box = (0, 0) # The first page requires extra vertical space for the headers if i == 0: - f_offset = header_img.height + description_box[1] + max(date_box[1], url_box[1]) + text_margin + description = textwrap.wrap(self.description, width=comic_width // description_size) + description_lines = len(description) + description_box = description_font.getbbox(max(description, key=len)) + description_box = (description_box[2] - description_box[0], (description_box[3] - description_box[1] + description_spacing) * (len(description) + 1)) + description = "\n".join(description) + + f_offset = header_img.height + description_box[1] + max(date_box[1], url_box[1]) + text_margin * 2 # Grab the image size while we are at it, for use outside of the loop img_size = img.size else: f_offset = 0 - f_img_size = (img.width, f_offset + img.height + caption_box[1] + text_margin) + f_img_size = (comic_width, f_offset + img.height + caption_box[1] + text_margin) f_img = Image.new("RGBA", f_img_size, (255, 255, 255, 255)) # Draw the headers as needed if i == 0: - f_img.paste(header_img, (0, 0)) - f_img.paste(safety_img, (0, header_img.height)) + #f_img.paste(background_img, (0, 0)) + f_img.paste(header_img, ((comic_width - header_img.width) // 2, 0)) # Draw the actual comic - f_img.paste(img, (0, f_offset)) + f_img.paste(img, ((comic_width - img.width) // 2, f_offset)) draw = ImageDraw.Draw(f_img) if i == 0: - # Draw the title - draw.text(((img.width - title_box[0]) // 2, header_img.height + 20), self.title, (0, 0, 0), font=title_font) + # Draw the description + draw.multiline_text(((comic_width - description_box[0]) // 2, header_img.height + 20), description, (0, 0, 0), spacing=description_spacing, font=description_font, align="center") # Draw the URL - draw.text((text_margin, header_img.height + safety_img.height + text_margin), self.url, (0, 0, 0), font=caption_font) + draw.text((text_margin, header_img.height + description_box[1] + text_margin), self.url, (0, 0, 0), font=caption_font) # Draw the date - draw.text((img.width - date_box[0] - text_margin, header_img.height + safety_img.height + text_margin), self.date.isoformat(), (0, 0, 0), align="right", font=caption_font) + draw.text((comic_width - date_box[0] - text_margin, header_img.height + description_box[1] + text_margin), self.date.isoformat(), (0, 0, 0), align="right", font=caption_font) # Draw the caption if self.captions[i]: - draw.multiline_text(((img.width - caption_box[0]) // 2, f_offset + img.height), caption, (0, 0, 0), spacing=caption_spacing, font=caption_font, align="center") + draw.multiline_text(((comic_width - caption_box[0]) // 2, f_offset + img.height), caption, (0, 0, 0), spacing=caption_spacing, font=caption_font, align="center") # Save the image f_image_path = NamedTemporaryFile(mode='wb', suffix=f"f_{i}.png", prefix=self.get_identifier_string(), delete = False) f_image_path.close()