Skip to content

Commit

Permalink
Add filesize check for the cover JPG
Browse files Browse the repository at this point in the history
The built cover is an SVG so isn’t being checked by `_lint_image_checks`, but the unbuilt cover image isn’t in src/epub/images so is also missing the file size check. This adds images/cover.jpg into those checks.
  • Loading branch information
robinwhittleton authored and acabal committed Aug 15, 2024
1 parent 6360ee6 commit c20711e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions se/se_epub_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,9 +1200,8 @@ def _lint_image_checks(self, filename: Path) -> list:
if image.size != (se.COVER_WIDTH, se.COVER_HEIGHT):
messages.append(LintMessage("f-017", f"[path][link=file://{self.path / 'images/cover.jpg'}]cover.jpg[/][/] must be exactly {se.COVER_WIDTH} × {se.COVER_HEIGHT}.", se.MESSAGE_TYPE_ERROR, filename))

# Run some tests on distributable images in ./src/epub/images/
# Once we reach Python 3.9 we can use path.is_relative_to() instead of this string comparison
if str(filename).startswith(str(self.content_path / "images")):
# Run some tests on distributable images in ./src/epub/images/ and the cover
if filename.is_relative_to(self.content_path / "images") or (self.path / "images" / "cover.jpg" == filename):
if os.path.getsize(filename) > 1500000: # 1.5MB
messages.append(LintMessage("f-016", "Image more than 1.5MB in size.", se.MESSAGE_TYPE_ERROR, filename))

Expand Down

0 comments on commit c20711e

Please sign in to comment.