Skip to content

Commit

Permalink
feat: added avif support
Browse files Browse the repository at this point in the history
  • Loading branch information
KojoZero committed Dec 31, 2024
1 parent ad8af0e commit 2073235
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
14 changes: 13 additions & 1 deletion mokuro/manga_page_ocr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import cv2
import numpy as np
import pillow_avif

Check failure on line 4 in mokuro/manga_page_ocr.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

mokuro/manga_page_ocr.py:4:8: F401 `pillow_avif` imported but unused
from PIL import Image
from loguru import logger
from scipy.signal.windows import gaussian
Expand Down Expand Up @@ -45,7 +47,17 @@ def __init__(
self.mocr = MangaOcr(pretrained_model_name_or_path, force_cpu)

def __call__(self, img_path):
img = imread(img_path)
# Check if the file is in AVIF format
# Create a temporary png path
img_path = str(img_path)
if img_path.lower().endswith('.avif'):
temp_path = img_path.replace('.avif', '_temp.png')
avif_img = Image.open(img_path)
avif_img.save(temp_path, 'PNG')
img = imread(temp_path)
os.remove(temp_path)
else:
img = imread(img_path)
if img is None:
raise InvalidImage()
H, W, *_ = img.shape
Expand Down
2 changes: 1 addition & 1 deletion mokuro/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def get_img_paths(self):
img_paths = natsorted(
p.relative_to(self.path_in)
for p in self.path_in.glob("**/*")
if p.is_file() and p.suffix.lower() in (".jpg", ".jpeg", ".png", ".webp")
if p.is_file() and p.suffix.lower() in (".jpg", ".jpeg", ".png", ".webp", ".avif")
)
img_paths = {p.with_suffix(""): p for p in img_paths}
return img_paths
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies = [
"numpy",
"opencv-python>=4.1.2",
"Pillow>=7.1.2",
"pillow-avif-plugin >= 1.4.6",
"pyclipper",
"requests",
"scipy",
Expand Down

0 comments on commit 2073235

Please sign in to comment.