最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I emulate gamma correction with CSS3 filters? - Stack Overflow

programmeradmin2浏览0评论

According to this page .asp there are contrast, brighness, hue, saturation, etc. But no explicit access to gamma. Is there a way to emulate it with the existing CSS3 image filters, or does exist a plugin (JQuery or other JS) which makes it possible?

According to this page http://www.w3schools./cssref/css3_pr_filter.asp there are contrast, brighness, hue, saturation, etc. But no explicit access to gamma. Is there a way to emulate it with the existing CSS3 image filters, or does exist a plugin (JQuery or other JS) which makes it possible?

Share Improve this question asked Feb 2, 2016 at 0:23 KonstantinKonstantin 3,1334 gold badges38 silver badges58 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

You can use svg filters

#filtered {
  filter: url('#gamma');
}
<img src="https://picsum.photos/seed/picsum/300/200">
<img id="filtered" src="https://picsum.photos/seed/picsum/300/200">

<svg height="0">
  <filter id="gamma">
    <feComponentTransfer>
       <feFuncR type="gamma" exponent="1.5" amplitude="2.5" offset="0" />
       <feFuncG type="gamma" exponent="1.5" amplitude="2.5" offset="0" />
       <feFuncB type="gamma" exponent="1.5" amplitude="2.5" offset="0" />
    </feComponentTransfer>
   </filter>
</svg>

Gamma is more closely related to contrast than anything. While there isn't explicitly a filter for it, you could get near identical results by using small adjustments to brightness and working with contrast primarily.

For example if I wanted to raise the gamma on an image that looks too dark I might try:

filter: contrast(125%) brightness(105%);

keeping in mind to use the brightness primarily to brighten up the darkness in the image, the contrast should be doing most of the work in the case that you want to closely emulate gamma.

Feel free to check out a topic asking about gamma vs brightness here: https://graphicdesign.stackexchange./questions/11445/gamma-vs-brightness-any-difference

Hope that helped. Cheers.

发布评论

评论列表(0)

  1. 暂无评论