I ran into a bug where, when using practical?.json in the examples subdirectory, cover.png in the created EPUB was corrupted compared to the PNG file at the provided URL. I tracked the bug down to this line in ebook/cover.py, make_cover_from_url():
if Image.open(cover).format != "PNG":
This call advances the "cover" stream (reading its first few bytes for detection), so if the condition is wrong, and "cover" is returned from the function, the later call to read() will not get these first few bytes. If the condition is true, trying to convert to PNG from the same stream should fail too, though I didn't test this.
To fix this, it was enough for me to change to Image.open(BytesIO(img.content)).format != "PNG":
thus using a separate stream for detection.
I want to note I'm seeing this bug when running the tool on the Linux subsystem inside Windows 10; I guess it might be possible that the behavior is different in other Python environments. I don't really know Python3 I/O so I decided to describe the problem rather than send a pull request.
I ran into a bug where, when using practical?.json in the examples subdirectory, cover.png in the created EPUB was corrupted compared to the PNG file at the provided URL. I tracked the bug down to this line in ebook/cover.py, make_cover_from_url():
if Image.open(cover).format != "PNG":
This call advances the "cover" stream (reading its first few bytes for detection), so if the condition is wrong, and "cover" is returned from the function, the later call to read() will not get these first few bytes. If the condition is true, trying to convert to PNG from the same stream should fail too, though I didn't test this.
To fix this, it was enough for me to change to Image.open(BytesIO(img.content)).format != "PNG": thus using a separate stream for detection.
I want to note I'm seeing this bug when running the tool on the Linux subsystem inside Windows 10; I guess it might be possible that the behavior is different in other Python environments. I don't really know Python3 I/O so I decided to describe the problem rather than send a pull request.