Giter Site home page Giter Site logo

klouskingsley / imagedata-filters Goto Github PK

View Code? Open in Web Editor NEW
26.0 5.0 1.0 73 KB

some filters for imagedata of canvas context2d

Home Page: https://klouskingsley.github.io/imagedata-filters/

License: MIT License

JavaScript 100.00%
filter css3 css3-filter canvas context imagedata blur brightness contrast grayscale

imagedata-filters's Introduction

imagedata-filters

imagedata-filters is a JavaScript library to operate canvas imagedata. It similar to css3 filter function.

中文文档

Install

Via npm

$ npm i imagedata-filters

Or download imagedata-filtes.min.js and include in your HTML

Usage

<img src="./example/atx.jpg" id="originImg">
<canvas id="filterImg" width="800" height="800">

<script src="./dist/imagedata-filters.min.js"></script>
<script>
    var originImg = document.getElementById('originImg')
    var filterImg = document.getElementById('filterImg')
    var filterCtx = filterImg.getContext('2d')

    filterCtx.drawImage(originImg, 0, 0)

    var imageData = filterCtx.getImageData(0, 0, filterImg.width, filterImg.height), {amount: 1.2}

    imagedataFilters.contrast(imageData, {amount: '1.2'})    // change imageData directly cause imageData.data is readonly

    filterCtx.putImageData(imageData, 0, 0)

</script>

Api

All the apis is similar to css3 filter function, the difference between css3 filter function and imagedata-filters function is that css3 function's argument is a css number value but imagedata-filters function's argument is an object which contains a key amount which is relevant to the css number value in css3 filter function.

.brightness(imageData, options)

.contrast(imageData, options)

.grayscale(imageData, options)

.hueRotate(imageData, options)

options.amount is a value of radian, this is different from css3 hue-rorate.

.invert(imageData, options)

.opacity(imageData, options)

.saturate(imageData, options)

.sepia(imageData, options)

.blur(imageData, options)

use blur carefully, because Gaussiam blur compute may has a performance issue with the increase of options.amount

License

MIT

中文文档

安装

通过npm安装

$ npm i imagedata-filters

或者直接下载imagedata-filtes.min.js并嵌入你的HTML页面中

使用

<img src="./example/atx.jpg" id="originImg">
<canvas id="filterImg" width="800" height="800">

<script src="./dist/imagedata-filters.min.js"></script>
<script>
    var originImg = document.getElementById('originImg')
    var filterImg = document.getElementById('filterImg')
    var filterCtx = filterImg.getContext('2d')

    filterCtx.drawImage(originImg, 0, 0)

    var imageData = filterCtx.getImageData(0, 0, filterImg.width, filterImg.height), {amount: 1.2}

    imagedataFilters.contrast(imageData, {amount: '1.2'})    // 因为imageData.data是只读的,所以这里会直接修改imageData.data

    filterCtx.putImageData(imageData, 0, 0)

</script>

Api

所有的api都和css3 filter中的函数类似,不同的是,css3 fitler函数的参数是一个css数值, 而imagedata-filters函数中的options是一个对象,它有一个amount的key,对应着css3 filter里面的那个参数.

.brightness(imageData, options)

.contrast(imageData, options)

.grayscale(imageData, options)

.hueRotate(imageData, options)

options.amount是一个弧度值,这一点与css3 hue-rorate不同。

.invert(imageData, options)

.opacity(imageData, options)

.saturate(imageData, options)

.sepia(imageData, options)

.blur(imageData, options)

使用blur时注意,因为随着options.amount的增大,高斯模糊的计算可能会有性能问题.

License

MIT

imagedata-filters's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

nicksun011

imagedata-filters's Issues

hueRotate

hueRotate

得出来的结果和css filter 不一致

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.