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

[Bug] img2pdf插件报错 #292

Open
2 tasks done
BrandenXia opened this issue Oct 9, 2024 · 5 comments
Open
2 tasks done

[Bug] img2pdf插件报错 #292

BrandenXia opened this issue Oct 9, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@BrandenXia
Copy link
Contributor

BrandenXia commented Oct 9, 2024

注意事项

  • 提ISSUE前,请确认你已经在GitHub Issues和Discussions里搜索过类似的问题,并且没找到想要的答案。
  • GitHub Actions问题请到置顶的Issue反馈。

发生Bug时,你的使用方式?

Python代码

你是否在禁漫官方网页或APP,验证过相应的功能是正常的?

我要反馈的bug无需验证/不方便验证

option配置+源码/命令

#!/usr/bin/env python3

import sys

import jmcomic

args = sys.argv[1:]

option = jmcomic.JmOption.construct(
    {
        "dir_rule": {"base_dir": "/somewhere/jm"},
        "download": {"image": {"suffix": ".jpg"}},
        "plugins": {
            "after_album": [
                {
                    "plugin": "img2pdf",
                    "kwargs": {
                        "pdf_dir": "/somewhere/jm",
                        "filename_rule": "Aname",
                    },
                }
            ]
        },
    },
    cover_default=True,
)

for arg in args:
    print("Downloading %s..." % arg)
    jmcomic.download_album(arg, option)

print("All downloads finished")

下载的是 615508

你预期的结果,与实际结果的差别

产生报错

[2024-10-09 08:20:57] [MainThread]:【plugin.error】插件 [img2pdf],运行遇到未捕获异常,异常信息: [cannot read input image (not jpeg2000). PIL: error reading image: cannot identify image file <_io.BytesIO object at 0x1059d0720>]
Traceback (most recent call last):
  File "/Users/someone/.rye/py/[email protected]/lib/python3.12/site-packages/img2pdf.py", line 1817, in read_images
    imgdata = Image.open(im)
              ^^^^^^^^^^^^^^
  File "/Users/someone/.rye/py/[email protected]/lib/python3.12/site-packages/PIL/Image.py", line 3498, in open
    raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x1059d0720>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/someone/.rye/py/[email protected]/lib/python3.12/site-packages/jmcomic/jm_option.py", line 546, in call_all_plugin
    self.invoke_plugin(pclass, kwargs, extra, pinfo)
  File "/Users/someone/.rye/py/[email protected]/lib/python3.12/site-packages/jmcomic/jm_option.py", line 589, in invoke_plugin
    self.handle_plugin_unexpected_error(e, pinfo, kwargs, plugin, pclass)
  File "/Users/someone/.rye/py/[email protected]/lib/python3.12/site-packages/jmcomic/jm_option.py", line 619, in handle_plugin_unexpected_error
    raise e
  File "/Users/someone/.rye/py/[email protected]/lib/python3.12/site-packages/jmcomic/jm_option.py", line 577, in invoke_plugin
    plugin.invoke(**kwargs)
  File "/Users/someone/.rye/py/[email protected]/lib/python3.12/site-packages/jmcomic/jm_plugin.py", line 766, in invoke
    img_path_ls, img_dir_ls = self.write_img_2_pdf(pdf_filepath, album, photo)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/someone/.rye/py/[email protected]/lib/python3.12/site-packages/jmcomic/jm_plugin.py", line 790, in write_img_2_pdf
    f.write(img2pdf.convert(img_path_ls))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/someone/.rye/py/[email protected]/lib/python3.12/site-packages/img2pdf.py", line 2733, in convert
    ) in read_images(
         ^^^^^^^^^^^^
  File "/Users/someone/.rye/py/[email protected]/lib/python3.12/site-packages/img2pdf.py", line 1829, in read_images
    raise ImageOpenError(
img2pdf.ImageOpenError: cannot read input image (not jpeg2000). PIL: error reading image: cannot identify image file <_io.BytesIO object at 0x1059d0720>
All downloads finished

其他信息

看报错估计是下载下来的图片格式问题,或者img2pdf库的问题(?

@BrandenXia BrandenXia added the bug Something isn't working label Oct 9, 2024
@hect0x7
Copy link
Owner

hect0x7 commented Oct 9, 2024

我使用你的代码直接运行成功了,没有报错
image

@hect0x7
Copy link
Owner

hect0x7 commented Oct 9, 2024

你看看下载下来的图片是否有空白图

@BrandenXia
Copy link
Contributor Author

我看了一下,图片都不是空的,检查了一下包的版本,也都是最新的

@BrandenXia
Copy link
Contributor Author

我等会试一下直接在repl里用img2pdf处理能不能复现

@BrandenXia
Copy link
Contributor Author

好像是img2pdf库的问题,我直接用PIL的Image.open,输入图片路径不会有问题,img2pdf是读成ByteIO再放到PIL的Image.open的,这个库也很久没维护了,可能在mac上不兼容新版本的PIL了?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants