2

I've been using the Stylish extension to Google Chrome to browse xkcd in dark. The user-style called Dark XKCD uses filter: invert(100%); to make the generally white images generally dark. However, invert messes with the colors, such as in this comic, which normally looks like this:

xkcd 681

But instead, it looks like this (snippet, as it's hard to simply save the image):

img {
  max-width: 70%; /* make image easily visible for demonstration */
  filter: invert(100%);
  -webkit-filter: invert(100%);
  -moz-filter: invert(100%);
}
<img src="https://imgs.xkcd.com/comics/gravity_wells.png"/>

The orange becomes blue!

I found hue-rotate, which semi-fixes it if I apply with invert:

img {
  max-width: 70%; /* make image easily visible for demonstration */
  filter: invert(100%) hue-rotate(180deg);
  -webkit-filter: invert(100%) hue-rotate(180deg);
  -moz-filter: invert(100%) hue-rotate(180deg);
}
<img src="https://imgs.xkcd.com/comics/gravity_wells.png"/>

However, it fails for other comics; for example, this one:

img {
  filter: invert(100%) hue-rotate(180deg);
  -webkit-filter: invert(100%) hue-rotate(180deg);
  -moz-filter: invert(100%) hue-rotate(180deg);
}
<img src="http://imgs.xkcd.com/comics/making_rules.png"/>

I can now fiddle with the hue of the image or the saturation and lightness together, but maybe if I could de-couple the inversion of the saturation and lightness, I could achieve better results.

How can I invert hue, saturation, or lightness without touching the others?

3
  • You realize blue is the inverse of orange right... and red to green, and violet to yellow. I know... don't really answer your question. But seeing orange replaced with blue after invert isn't really abnormal. :)
    – Scott
    Commented Feb 9, 2016 at 6:03
  • @SOIA I know; I'm just trying to fiddle with the image to make it overall darker without affecting the colors (as much as possible). I understand invert inverts the color, but I want to keep the colors the same; dark mode on XKCD :-)
    – Justin
    Commented Feb 9, 2016 at 6:04
  • @Justin Did you get any solution for this issue? Commented Jul 21, 2022 at 7:06

1 Answer 1

1

You can't do HSL operations in filters - they're RGB only. Filters hue rotate is a (generally bad) approximation of a true hue rotation using RGB space. There are somewhat complex things you can do in filters to "color-separate" out colored areas from greys/whites, invert the separately and then recombine. But it's not a great general solution.

Not the answer you're looking for? Browse other questions tagged or ask your own question.