6.0.7 • Published 3 months ago

react-native-color-matrix-image-filters v6.0.7

Weekly downloads
10,740
License
MIT
Repository
github
Last release
3 months ago

react-native-color-matrix-image-filters

npm version build publish Type Coverage Libraries.io dependency status for latest release npm

Various color matrix based image filters for iOS & Android.

Status

  • iOS & Android:
    • filter components work as wrappers for Image, ImageBackground and react-native-fast-image components
    • doesn't support gif format on iOS
  • react-native:
    • supported versions: ">=0.60.0"
    • supports both "old" and "new" architecture

Getting started

1. Install latest version from npm

npm i react-native-color-matrix-image-filters

2. Install pods

if using "old" architecture:

npx pod-install

if using "new" architecture:

RCT_NEW_ARCH_ENABLED=1 npx pod-install

Scope

This module is meant to be used for simple stuff, like "grayscaling inactive user avatar" etc. Check react-native-image-filter-kit if you need some advanced features like image blending/composing, extracting filtering results to file system and ability to create custom filters.

Example

import { Image } from 'react-native'
import {
  Grayscale,
  Sepia,
  Tint,
  ColorMatrix,
  concatColorMatrices,
  invert,
  contrast,
  saturate
} from 'react-native-color-matrix-image-filters'

const GrayscaledImage = (imageProps) => (
  <Grayscale>
    <Image {...imageProps} />
  </Grayscale>
)

const CombinedFiltersImage = (imageProps) => (
  <ColorMatrix matrix={concatColorMatrices(sepia(), tint(1.25))}>
    <Image {...imageProps} />
  </ColorMatrix>
)

const ColorMatrixImage = (imageProps) => (
  <ColorMatrix matrix={concatColorMatrices(saturate(-0.9), contrast(5.2), invert())}>
    <Image {...imageProps} />
  </ColorMatrix>
)
OriginalGrayscaled
CombinedFiltersColorMatrix

Usage

Each filter support all of View props. Also some filters have optional amount prop which takes a number. ColorMatrix filter has matrix prop which takes a Matrix - an array of 20 numbers. Additionally library exports functions like grayscale, tint etc. - these functions return values of Matrix type and their results can be combined with concatColorMatrices function.

Reference

Supported filters

ComponentAdditional propsfunction
ColorMatrixmatrix: Matrix-
Normal-normal(): Matrix
RGBAred: number = 1, green: number = 1, blue: number = 1, alpha: number = 1rgba(red: number = 1, green: number = 1, blue: number = 1, alpha: number = 1): Matrix
Saturateamount: number = 1saturate(amount: number = 1): Matrix
HueRotateamount: number = 0hueRotate(amount: number = 0): Matrix
LuminanceToAlpha-luminanceToAlpha(): Matrix
Invert-invert(): Matrix
Grayscaleamount: number = 1grayscale(amount: number = 1): Matrix
Sepiaamount: number = 1sepia(amount: number = 1): Matrix
Nightvision-nightvision(): Matrix
Warm-warm(): Matrix
Cool-cool(): Matrix
Brightnessamount: number = 1brightness(amount: number = 1): Matrix
Contrastamount: number = 1contrast(amount: number = 1): Matrix
Temperatureamount: number = 1temperature(amount: number = 1): Matrix
Tintamount: number = 0tint(amount: number = 0): Matrix
Thresholdamount: number = 0threshold(amount: number = 0): Matrix
Technicolor-technicolor(): Matrix
Polaroid-polaroid(): Matrix
ToBGR-toBGR(): Matrix
Kodachrome-kodachrome(): Matrix
Browni-browni(): Matrix
Vintage-vintage(): Matrix
Nightamount: number = 0.1night(amount: number = 0.1): Matrix
Predatoramount: number = 1predator(amount: number = 1): Matrix
Lsd-lsd(): Matrix
ColorTonedesaturation: number = 0.2, toned: number = 0.15, lightColor: string = "#FFE580", darkColor: string = "#338000"colorTone(desaturation: number = 0.2, toned: number = 0.15, lightColor: string = "#FFE580", darkColor: string = "#338000"): Matrix
DuoTonefirstColor: string = "#FFE580", secondColor: string = "#338000"duoTone(firstColor: string = "#FFE580", secondColor: string = "#338000"): Matrix
Protanomaly-protanomaly(): Matrix
Deuteranomaly-deuteranomaly(): Matrix
Tritanomaly-tritanomaly(): Matrix
Protanopia-protanopia(): Matrix
Deuteranopia-deuteranopia(): Matrix
Tritanopia-tritanopia(): Matrix
Achromatopsia-achromatopsia(): Matrix
Achromatomaly-achromatomaly(): Matrix

Functions

  • concatColorMatrices(...matrices: Matrix[]): Matrix

Matrix type

  • A 4x5 matrix for color transformations represented by array - consult Android docs for more specific info about it's format

Misc

  • This library was tested only with standard Image component, but in theory it should work with any image that conforms to CMIFImageView protocol or is based on Android ImageView class
  • Installing react-native-fast-image is not required - this module doesn't depend on it

Credits

6.0.7

3 months ago

6.0.6

3 months ago

6.0.5

4 months ago

6.0.1

1 year ago

6.0.0

2 years ago

6.0.3

1 year ago

6.0.2

1 year ago

5.2.14

2 years ago

5.2.13

2 years ago

5.2.10

3 years ago

5.2.9

3 years ago

5.2.5

4 years ago

5.2.4

4 years ago

5.2.2

4 years ago

5.2.0

5 years ago

5.1.7

5 years ago

5.1.6

5 years ago

5.1.5

5 years ago

5.1.4

5 years ago

5.1.3

5 years ago

5.0.12

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.0.0

6 years ago

3.0.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago