I am trying to change image to red color using css. This is what I have so far
img {
-webkit-filter: invert(90%); filter: invert(90%);
}
I am trying to change image to red color using css. This is what I have so far
img {
-webkit-filter: invert(90%); filter: invert(90%);
}
you need to combine two filters saturate
and hue
, below is a possible combination to get a "red" (if you use a color picker it will generate the default web "red" - #FF0000
or just #F00
, because you can choose your red, stronger or lighter.
img {
webkit-filter: saturate(100) hue-rotate(-140deg);
filter: saturate(100) hue-rotate(-140deg)
}
<img class="screencap" src="https://i.stack.imgur.com/speoA.png">
In the first snippet had, allegedly, a bug (after a chat with @kaiido), that was just making red in FF using Windows in tag img
- while keeping pink in other browsers in other OSs, (therefore I'm going to file the bug in bugzilla)
So there is a way to do this working cross browser, using mixed filters
img {
-webkit-filter: brightness(0.6)contrast(3.4)hue-rotate(217deg)saturate(9.9);
filter: brightness(0.6)contrast(3.4)hue-rotate(217deg)saturate(9.9);
}
<img class="screencap" src="https://i.stack.imgur.com/speoA.png">
changing the color of a PNG image with some filter styles
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
body {
background-color: #03030a;
min-width: 800px;
min-height: 400px
}
img {
width: 20%;
float: left;
margin: 0;
}
/*Filter styles*/
.saturate {
filter: saturate(3);
-webkit-filter: saturate(3);
}
.grayscale {
filter: grayscale(100%);
-webkit-filter: grayscale(100%);
}
.contrast {
filter: contrast(160%);
-webkit-filter: contrast(160%);
}
.brightness {
filter: brightness(0.25);
-webkit-filter: brightness(0.25);
}
.blur {
filter: blur(3px);
-webkit-filter: blur(3px);
}
.invert {
filter: invert(100%);
-webkit-filter: invert(100%);
}
.sepia {
filter: sepia(100%);
-webkit-filter: sepia(100%);
}
.huerotate {
filter: hue-rotate(180deg);
-webkit-filter: hue-rotate(180deg);
}
.opacity {
filter: opacity(50%);
-webkit-filter: opacity(50%);
}
</style>
</head>
<body>
<h2>Change PNG image color</h2>
<img alt="Mona Lisa" src="https://i.stack.imgur.com/OyP0g.jpg" title="original">
<img alt="Mona Lisa" src="https://i.stack.imgur.com/OyP0g.jpg" title="saturate" class="saturate">
<img alt="Mona Lisa" src="https://i.stack.imgur.com/OyP0g.jpg" title="grayscale" class="grayscale">
<img alt="Mona Lisa" src="https://i.stack.imgur.com/OyP0g.jpg" title="contrast" class="contrast">
<img alt="Mona Lisa" src="https://i.stack.imgur.com/OyP0g.jpg" title="brightness" class="brightness">
<img alt="Mona Lisa" src="https://i.stack.imgur.com/OyP0g.jpg" title="blur" class="blur">
<img alt="Mona Lisa" src="https://i.stack.imgur.com/OyP0g.jpg" title="invert" class="invert">
<img alt="Mona Lisa" src="https://i.stack.imgur.com/OyP0g.jpg" title="sepia" class="sepia">
<img alt="Mona Lisa" src="https://i.stack.imgur.com/OyP0g.jpg" title="huerotate" class="huerotate">
<img alt="Mona Lisa" src="https://i.stack.imgur.com/OyP0g.jpg" title="opacity" class="opacity">
</body>
</html>
You have to use filter function to give color to image. for example convert white to black and vice versa, use like it filter .invert(100%).
img {
filter: saturate(100) hue-rotate(241.5deg);
}