Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 06-13-2025, 01:16 AM   #1
Slevin#7
Enthusiast
Slevin#7 began at the beginning.
 
Posts: 38
Karma: 10
Join Date: May 2025
Device: iPad
How to Handle Transparent Images for Dark Mode?

I have some transparent PNG images (text-dividers and simple grafics). These images are no pictures but only simple drawings.

Since I wanna make sure that they can be seen and read in dark mode as well I've created two versions, one with black lines and text for the light mode and one in white for the dark mode. Both images have a transparent background to fit in nicely in the current active desgin.

While Apple Books displays the images correctly, Google Play Books won't comply in dark mode. Although Google Play Books grabs the intended image for the dark mode, it will add a light background to it for no reason, making the image a light square and completely unreadable, since the image for the dark mode consists only of white content.

How can I insist Google Play Books to keep their fingers off the image and leave it in original state? I'll get it, that Google thinks we developers are too stupid to cover these details, but what, if there are some eBook creators out there in the wild who actually know what they are doing (or at least think to know)?

I don't wanna create an extra version for dark mode without transparent background but dark background, since the background color set on the device varies.

How do you guys handle this issue for readers which do alter transparent images?

For testing reasons I've added an eBook which contains a text-divider which serves for both light and dark mode (the grafic is black and white for this purpose), and a line drawing in two versions, one for light and one for dark.
Attached Files
File Type: epub transparency-test.epub (43.0 KB, 11 views)
Slevin#7 is offline   Reply With Quote
Old 06-13-2025, 12:00 PM   #2
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,736
Karma: 8700123
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by Slevin#7 View Post
I have some transparent PNG images (text-dividers and simple grafics). These images are no pictures but only simple drawings.

Since I wanna make sure that they can be seen and read in dark mode as well I've created two versions, one with black lines and text for the light mode and one in white for the dark mode. Both images have a transparent background to fit in nicely in the current active desgin.

While Apple Books displays the images correctly, Google Play Books won't comply in dark mode. Although Google Play Books grabs the intended image for the dark mode, it will add a light background to it for no reason, making the image a light square and completely unreadable, since the image for the dark mode consists only of white content.

How can I insist Google Play Books to keep their fingers off the image and leave it in original state? I'll get it, that Google thinks we developers are too stupid to cover these details, but what, if there are some eBook creators out there in the wild who actually know what they are doing (or at least think to know)?

I don't wanna create an extra version for dark mode without transparent background but dark background, since the background color set on the device varies.

How do you guys handle this issue for readers which do alter transparent images?

For testing reasons I've added an eBook which contains a text-divider which serves for both light and dark mode (the grafic is black and white for this purpose), and a line drawing in two versions, one for light and one for dark.
The problem here is that not all ereaders honor "@media (prefers-color-scheme: dark)" and so never your transparent .png for dark mode is enabled. If "@media (prefers-color-scheme: dark)" were honored, and you don't want to have two transparent .png (one for light, one for dark mode), you can appy the property "filter: invert(1) hue-rotate(180deg);" to your light mode png. Google Play Books is an awful ereader; its support for epub3 is very limited (and your ebooks are epub3) so don't expect much regarding to what Google Play Books can offer.

I made some minor modifications to the epub you uploaded, and it works in CHROME and FIREBOX Try the following test:

1. Open the epub in Sigil.
2. Right-click on the Section0001.xhtml sheet and select "Open with..."
3. Choose to open that file with Chrome or Firefox.

Why did I tell you to open that sheet with one of those browsers? Because they handle "@media (prefers-color-scheme: dark)" well, and if you change the light mode to dark mode and vice versa, you'll see that everything appears as expected.

The problem is e-readers that don't respect @media and don't detect the change to dark mode.
Attached Files
File Type: epub transparency-test bis.epub (29.1 KB, 8 views)
RbnJrg is online now   Reply With Quote
Old 06-13-2025, 12:55 PM   #3
Slevin#7
Enthusiast
Slevin#7 began at the beginning.
 
Posts: 38
Karma: 10
Join Date: May 2025
Device: iPad
Quote:
Originally Posted by RbnJrg View Post
"filter: invert(1) hue-rotate(180deg);"
This is great advice, many thanks. I'd have to make some smaller additional changes since pure white is too much of a contrast, but modern CSS filter might be a viable way.

The problem with Google Play Books was not that it didn't respect the media query but altered the background without any reason. Google might be thinking to provide a better contrast, but dind't realize there was a specific image exactly for that purpose.

Now, let me ask the 1 million dollar question: what will Kindle do? Is Kindle able to manage media queries and modern CSS like "filter: invert" etc.? And what about the other usual readers, can they handle this solution, or might it still bebetter to provide 2 distinct images for light and dark?
Slevin#7 is offline   Reply With Quote
Old 06-13-2025, 12:57 PM   #4
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,346
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
You can also try using a mask. This was talked about a bit in this thread.

and here.


That allows the image to be seen regardless of the light/dark mode, and you don't need to make multiple images.
Turtle91 is offline   Reply With Quote
Old 06-13-2025, 01:53 PM   #5
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,736
Karma: 8700123
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by Slevin#7 View Post
This is great advice, many thanks. I'd have to make some smaller additional changes since pure white is too much of a contrast, but modern CSS filter might be a viable way.
Employ "filter: invert(0.8)"

Quote:
Now, let me ask the 1 million dollar question: what will Kindle do? Is Kindle able to manage media queries and modern CSS like "filter: invert" etc.?
Kindle doesn't support transparent .png so you can't apply "filter: invert(x)" on them. Even if Kindle were to support "@media(prefers-color-scheme: dark)," there's no way to take advantage of this unless you use .jpg images with a white background and black colors for light mode, and images with a black background and white colors for dark mode, with the former showing and the latter hiding. But that's not a acceptable solution either.

Quote:
And what about the other usual readers, can they handle this solution, or might it still bebetter to provide 2 distinct images for light and dark?
AFAIK, so far none of the e-readers can adequately handle code that allows images to adapt to the user's display mode. Your only option is to work in epub3, using JS to detect the background color, and then display .pgn files that adapt to that background color.
RbnJrg is online now   Reply With Quote
Old 06-13-2025, 03:32 PM   #6
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,736
Karma: 8700123
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by Turtle91 View Post
You can also try using a mask. This was talked about a bit in this thread.

and here.


That allows the image to be seen regardless of the light/dark mode, and you don't need to make multiple images.
The approach is elegant and very clever, but the problem is that, like the others (including mine), it doesn't work on e-readers. It looks fine in Sigil, but if you change the background color in one of its plugins (e.g., Readium), you'll see that the image doesn't react to it. The same happens in Thorium and Calibre Viewer. It also has issues in Chrome and Firefox. Ideally, @media (prefers-color-scheme: dark) would work, but e-readers don't receive the change to the dark/light theme .
RbnJrg is online now   Reply With Quote
Old 06-13-2025, 07:02 PM   #7
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,346
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
I didn’t look recently, but I thought using the mask tied the mask color to the font color. Whatever color was selected with the theme would change the image. It didn’t specifically react to just background color.
Turtle91 is offline   Reply With Quote
Old 06-13-2025, 07:40 PM   #8
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,736
Karma: 8700123
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by Turtle91 View Post
I didn’t look recently, but I thought using the mask tied the mask color to the font color. Whatever color was selected with the theme would change the image. It didn’t specifically react to just background color.
And you are right. In Sigil, it works as expected but in ereader, it doesn't. Do the try in Thorium or Calibre Viewer, change the color theme and you'll see how masks work (or better said, don't work). The solution you posted is bright, a real pity that ereaders don't honor it.
RbnJrg is online now   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Comfy Dark Mix (Dark mode only) Comfy.n Calibre 30 12-01-2024 10:23 PM
Trouble with transparent images erasmix Writers' Corner 0 06-04-2023 02:00 AM
Randomly changing from Dark Mode to Light Mode C8H10N4O2 Calibre 2 07-28-2022 09:36 PM
Bug: Dark Mode (Windows) Book Details Pop-Up Cover Background Not Changing to Dark cgrapski Calibre 7 05-03-2021 11:45 PM
Transparent images Iznogood ePub 3 12-31-2012 08:38 PM


All times are GMT -4. The time now is 07:25 PM.


MobileRead.com is a privately owned, operated and funded community.