diff --git a/se/images.py b/se/images.py index 41ca9566..dc0f200f 100644 --- a/se/images.py +++ b/se/images.py @@ -150,12 +150,19 @@ def has_transparency(image: Image_type) -> bool: if image.mode == "P": transparent = image.info.get("transparency", -1) - for _, index in image.getcolors(): - if index == transparent: - return True - elif image.mode == "RGBA": + if isinstance(transparent, bytes): + for _, index in image.getcolors(): + if index >= len(transparent): + return False + if transparent[index] < 255: + return True + else: + for _, index in image.getcolors(): + if index == transparent: + return True + elif image.mode in ("LA", "RGBA"): extrema = image.getextrema() - if extrema[3][0] < 255: + if extrema[-1][0] < 255: return True return False diff --git a/tests/lint/filesystem/f-019/golden/f-019-out.txt b/tests/lint/filesystem/f-019/golden/f-019-out.txt new file mode 100644 index 00000000..5b333e2d --- /dev/null +++ b/tests/lint/filesystem/f-019/golden/f-019-out.txt @@ -0,0 +1,8 @@ +f-019 [Error] illustration-1.png `.png` file without transparency. Hint: If an +image doesn’t have transparency, it should be saved as a `.jpg`. +f-019 [Error] illustration-6.png `.png` file without transparency. Hint: If an +image doesn’t have transparency, it should be saved as a `.jpg`. +f-019 [Error] illustration-7.png `.png` file without transparency. Hint: If an +image doesn’t have transparency, it should be saved as a `.jpg`. +f-019 [Error] illustration-8.png `.png` file without transparency. Hint: If an +image doesn’t have transparency, it should be saved as a `.jpg`. diff --git a/tests/lint/filesystem/f-019/in/src/epub/content.opf b/tests/lint/filesystem/f-019/in/src/epub/content.opf new file mode 100644 index 00000000..cd1bc1ad --- /dev/null +++ b/tests/lint/filesystem/f-019/in/src/epub/content.opf @@ -0,0 +1,101 @@ + + + + url:https://standardebooks.org/ebooks/jane-austen/unknown-novel + 1900-01-01T00:00:00Z + 1900-01-01T00:00:00Z + The source text and artwork in this ebook are believed to be in the United States public domain; that is, they are believed to be free of copyright restrictions in the United States. They may still be copyrighted in other countries, so users located outside of the United States must check their local laws before using this ebook. The creators of, and contributors to, this ebook dedicate their contributions to the worldwide public domain via the terms in the [CC0 1.0 Universal Public Domain Dedication](https://creativecommons.org/publicdomain/zero/1.0/). + Standard Ebooks + Standard Ebooks + https://standardebooks.org + bkd + mdc + pbl + The League of Moveable Type + League of Moveable Type, The + https://www.theleagueofmoveabletype.com + tyd + + Standard Ebooks + textual + textual + readingOrder + structuralNavigation + tableOfContents + unlocked + none + This publication conforms to WCAG 2.2 Level AA. + + Unknown Novel + Unknown Novel + England--Social life and customs--19th century--Fiction + Sisters -- Fiction + LCSH + sh2008114941 + LCSH + sh2008111400 + Fiction + A short test novel for lint testing. + + <p>A short test novel for lint testing.</p> + + en-GB + https://www.gutenberg.org/ebooks/161 + https://archive.org/details/bub_gb_RtT0OLKFMHsC + WORD_COUNT + READING_EASE + https://en.wikipedia.org/wiki/Unknown_Jane_Austen_Novel + https://github.com/standardebooks/jane-austen_unknown-novel + Jane Austen + Austen, Jane + https://en.wikipedia.org/wiki/Jane_Austen + http://id.loc.gov/authorities/names/n79032879 + aut + Georg Friedrich Kersting + Kersting, Georg Friedrich + https://en.wikipedia.org/wiki/Georg_Friedrich_Kersting + http://id.loc.gov/authorities/names/n83319941 + art + Anonymous + Anonymous + trc + John Doe + Doe, John + bkp + blw + cov + mrk + pfr + tyg + wat + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/lint/filesystem/f-019/in/src/epub/images/illustration-1.png b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-1.png new file mode 100644 index 00000000..64022b2c Binary files /dev/null and b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-1.png differ diff --git a/tests/lint/filesystem/f-019/in/src/epub/images/illustration-2.png b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-2.png new file mode 100644 index 00000000..3f04b66c Binary files /dev/null and b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-2.png differ diff --git a/tests/lint/filesystem/f-019/in/src/epub/images/illustration-3.png b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-3.png new file mode 100644 index 00000000..c0ac042c Binary files /dev/null and b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-3.png differ diff --git a/tests/lint/filesystem/f-019/in/src/epub/images/illustration-4.png b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-4.png new file mode 100644 index 00000000..ef281da0 Binary files /dev/null and b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-4.png differ diff --git a/tests/lint/filesystem/f-019/in/src/epub/images/illustration-5.png b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-5.png new file mode 100644 index 00000000..f410fcbd Binary files /dev/null and b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-5.png differ diff --git a/tests/lint/filesystem/f-019/in/src/epub/images/illustration-6.png b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-6.png new file mode 100644 index 00000000..d1e25a0e Binary files /dev/null and b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-6.png differ diff --git a/tests/lint/filesystem/f-019/in/src/epub/images/illustration-7.png b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-7.png new file mode 100644 index 00000000..959a1069 Binary files /dev/null and b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-7.png differ diff --git a/tests/lint/filesystem/f-019/in/src/epub/images/illustration-8.png b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-8.png new file mode 100644 index 00000000..f4261253 Binary files /dev/null and b/tests/lint/filesystem/f-019/in/src/epub/images/illustration-8.png differ diff --git a/tests/lint/filesystem/f-019/in/src/epub/text/chapter-1.xhtml b/tests/lint/filesystem/f-019/in/src/epub/text/chapter-1.xhtml new file mode 100644 index 00000000..b723fb85 --- /dev/null +++ b/tests/lint/filesystem/f-019/in/src/epub/text/chapter-1.xhtml @@ -0,0 +1,22 @@ + + + + I + + + + +
+

I

+

We can assume that any instance of a point can be construed as a themeless fisherman. Framed in a different way, some picked shakes are thought of simply as crabs. Nowhere is it disputed that a dinner sees a modem as a warming customer. The zeitgeist contends that we can assume that any instance of a kenneth can be construed as an entranced belgian. A rotate is a gaumless debt.

+

Not transparent.

+

Transparent.

+

Transparent.

+

Transparent.

+

Transparent.

+

Not transparent.

+

Not transparent.

+

Not transparent.

+
+ +