jQuery: there is a way to apply colour (tint) to an image?

前端 未结 4 1840
长发绾君心
长发绾君心 2020-11-29 12:33

there is a way to colour (apply tint) an image using jQ or some plugs? thank you

相关标签:
4条回答
  • 2020-11-29 12:47

    Simplest way I can think of is overlaying a semitransparent div over the image.

    A little example:

    HTML

    <div id="overlay" class="overlay"></div>
    <img id="myimg" src="img.jpg" />
    

    CSS

    .overlay
        {
        display: block;
        position: absolute;
        background-color: rgba(200, 100, 100, 0.5);
        top: 0px;
        left: 0px;
        width: 0px;
        height: 0px;
        }
    

    JS (with JQuery)

    overlay = $("#overlay");
    img = $("#myimg");
    overlay.width(img.css("width"));
    overlay.height(img.css("height"));
    overlay.css("top", img.offset().top + "px");
    overlay.css("left", img.offset().left + "px");
    
    0 讨论(0)
  • 2020-11-29 12:50

    I'm not sure if you're using PHP, but it's not possible with JavaScript/jQuery. With PHP, you can use the GD image library to tint the image before it's sent to the client. This thread should help :-)

    Also, this forum thread talks about ImageMagick to tint the image as well.

    I'm very sorry if you aren't/can't use PHP, however JavaScript can't do what you want.

    James

    0 讨论(0)
  • 2020-11-29 12:52

    As already mentioned in Dynamically changing image colours

    take a look at Pixastic (coloradjust)

    https://github.com/jseidelin/pixastic

    http://www.pixastic.com/lib/docs/actions/coloradjust/

    or PaintbrushJS (colour tint)

    https://github.com/mezzoblue/PaintbrushJS

    http://mezzoblue.github.com/PaintbrushJS/demo/

    0 讨论(0)
  • 2020-11-29 13:00

    nico's answer is great if you're after a simple tinge of a colour - however, if you're talking about desaturating an image and then applying a tint (so that the image is only in green for example) then you can have a look at image manipulation with <canvas>

    After some googling, I found this library for canvas that focuses on photo manipulation operations: https://github.com/meltingice/CamanJS

    0 讨论(0)
提交回复
热议问题