简体   繁体   English

使用 html5/CSS/JS 的图像亮度

[英]Image brightness with html5/CSS/JS

In my project, I'm trying to create an ambient lighting feel.在我的项目中,我试图创造一种环境照明的感觉。 I handle images via client side coding and I need to adjust brightness of several images.我通过客户端编码处理图像,我需要调整几个图像的亮度。 I know there are libraries such as Pixastic, but I want a solution which applies directly into HTML code(like tags) rather than Image objects in JS.我知道有诸如 Pixastic 之类的库,但我想要一个直接应用于 HTML 代码(如标签)而不是 JS 中的 Image 对象的解决方案。 Are there any Javascript or CSS based way to do it?是否有任何基于 Javascript 或 CSS 的方法来做到这一点?

You can try playing around with CSS opacity to see if that suits your needs.您可以尝试使用 CSS 不透明度来查看是否适合您的需求。

img {
    opacity: 0.8; /* good browsers */
    filter: alpha(opacity=80); /* ye 'old IE */
}

As Blender suggests, the <canvas> tag is what you want for gamma manipulation, which is a non-linear per-pixel transformation.正如 Blender 所建议的, <canvas>标签是您想要进行伽玛操作的标签,这是一种非线性的每像素转换。

Here is one with HTML5.这是一款带有 HTML5 的产品。

Checkout the one for brightness adjustment.查看用于亮度调节的那个。

https://www.html5rocks.com/en/tutorials/canvas/imagefilters/ https://www.html5rocks.com/en/tutorials/canvas/imagefilters/

Filters.brightness = function(pixels, adjustment) {
  var d = pixels.data;
  for (var i=0; i<d.length; i+=4) {
    d[i] += adjustment;
    d[i+1] += adjustment;
    d[i+2] += adjustment;
  }
  return pixels;
};

First of all, if Pixastic can work on the results of new Image it can work on <img> elements in the document too.首先,如果 Pixastic 可以处理new Image的结果,它也可以处理文档中的<img>元素。

Your options other than that are basically canvas imagedata manipulation (which won't work in IE8 or older) and SVG filters (which won't work in IE8 or older, and won't work on HTML elements directly in anything but Gecko).除此之外,您的选择基本上是 canvas 图像数据操作(在 IE8 或更早版本中不起作用)和 SVG 过滤器(在 IE8 或更早版本中不起作用,并且除了 Geck4AD5FCA2E03A3F74ZDBB1CED 之外的任何其他元素都不能直接起作用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM