Giter Club home page Giter Club logo

cc-gram's Introduction

CCgram Logo

๐Ÿ–ผ CCgram

NPM Version NPM Downloads Test Status License

Buy Me A Coffee

A CSS & Canvas Instagram filter inspired by CSSgram

๐Ÿ”— https://eastsun5566.github.io/cc-gram/

Demo GIF

๐Ÿค” Why

CSSgram is an excellent CSS filter library. However, there are instances where you might need to access or download the image with filter. This is where CCgram comes into play. It enables you to preview filter using pure CSS and draw them with Canvas whenever you need to.

  • On-Demand: Utilizes CSS for previewing and draws with the Canvas API as needed
  • Non-Blocking: Images are drawn on a Web Worker using OffscreenCanvas & ImageBitmap

โœจ Installation

npm i cc-gram

๐Ÿš€ Usage

Apply CSS filter

HTML

An image tag with data-filter attribute is filter name

<img src="./my-picture.png" data-filter="1977" />

JavaScript

Initialize to apply CSS filter to All targets has data-filter attribute

import { createFilter } from "cc-gram";

const filter = createFilter();
// or you can turn off init apply
const filter = createFilter({ init: false });

// you can also specify data attribute
// i.e., <img data-my-attr="1977">
const filter = createFilter({ dataAttribute: "my-attr" });

Manual apply CSS filter

applyFilter()

// apply to All targets has `data-filter` attribute
filter.applyFilter();

// or you can just use selector for performance
filter.applyFilter("#my-image");
All available filter name list

filterNames

const filterNames = filter.filterNames;
  • Default filter Name list:

    • aden
    • inkwell
    • reyes
    • gingham
    • toaster
    • walden
    • hudson
    • earlybird
    • mayfair
    • lofi
    • 1977
    • brooklyn
    • xpro2
    • nashville
    • lark
    • moon
    • clarendon
    • willow
    • rise
    • slumber
    • brannan
    • valencia
    • maven
    • stinson
    • amaro
Add / Set filter to the filter list

setFilter(name, setting)

  • name: string - The filter name
  • setting: object - The filter setting
filter.setFilter("my-filter", {
  saturate: 0.8,
  contrast: 1.2,
});
  • Available setting key (all value is number):

    • blur
    • brightness
    • contrast
    • grayscale
    • hue-rotate
    • invert
    • saturate
    • sepia
Remove the filter from the filter list

removeFilter(name)

  • name: string - The filter name
filter.removeFilter("my-filter");

Access image with filter

const image = document.querySelector('img[data-filter="1977"]');

Data URL

getDataURL(image[, options = {}])

const dataUrl = await filter.getDataURL(image);

Blob

getBlob(image[, options = {}])

const blob = await filter.getBlob(image, {
  type: "image/jpeg",
  quality: 0.8,
});
  • Options

    • type: string - MIME types, defaults to image/png,
    • quality: number- [0 - 1], defaults to 0.92

๐Ÿ”ง Development

# install deps
pnpm i

# fix style
pnpm run lint

# run test
pnpm test

# build for prod
pnpm run build

cc-gram's People

Contributors

dependabot[bot] avatar eastsun5566 avatar

Stargazers

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

Watchers

 avatar  avatar

Forkers

chenz24 buzz-dee

cc-gram's Issues

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.