Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added avif support #119

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 # noqa: F401
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
Loading