🔔 Alert..!! Get 2 Month Free Cloud Hosting With $200 Bonus From Digital Ocean ACTIVATE DEAL

The React Native Image Filter Kit provides various image filters for iOS & Android. Installation: # NPM $ npm install react-native-image-filter-kit –save Preview:

Featured Image React Native

Documentation

react-native-image-filter-kit

npm version CircleCI js-standard-style Dependency Status devDependencies Status typings included npm

Various image filters for iOS & Android.

Status

  • iOS & Android:
    • filter components work as combinable wrappers for standard Image and ImageBackground components
    • resulting images are being cached in memory
    • additional filters can be developed as separate modules
  • react-native:
    • supported versions:

      react-native min Android SDK min iOS version
      >=0.60.0 21 9.0
      >=0.57.1 <0.60.0 17 9.0

Installation

with react-native ">=0.60.0"

1. Install latest version from npm

$ npm i react-native-image-filter-kit -S

2. Install pods

$ cd ios && pod install && cd ..

3. Final steps

  • Open android/build.gradle and change minSdkVersion to 21.
  • If you are upgrading from rnifk v0.4.x open android/app/build.gradle and disable renderscript support mode in defaultConfig. Currently it is impossible to use support mode with androidx package due to bugs - 1, 2
with react-native ">=0.58.0 <0.60.0"

1. Install v0.4.14 from npm

$ npm i [email protected] -S

2-a. Link native modules

$ react-native link react-native-image-filter-kit

2-b. Install pods

If you use Cocoapods add the following line to your Podfile:

pod 'React', :path => '../node_modules/react-native' pod 'RNImageFilterKit', :path => '../node_modules/react-native-image-filter-kit'

$ cd ios && pod install && cd ..

2-c. Manual installation

Install manually if react-native link failed - link

3. Final steps

  • Open android/build.gradle and change minSdkVersion to 17.

  • Open android/app/build.gradle and change defaultConfig:

    defaultConfig {     ...     renderscriptTargetApi 21     renderscriptSupportModeEnabled true }
with react-native ">=0.57.1 <0.58.0"

1. Install v0.3.9 from npm

$ npm i [email protected] -S

2-a. Link native modules

$ react-native link react-native-image-filter-kit

2-b. Install pods

If you use Cocoapods add the following line to your Podfile:

pod 'React', :path => '../node_modules/react-native' pod 'RNImageFilterKit', :path => '../node_modules/react-native-image-filter-kit'

$ cd ios && pod install && cd ..

2-c. Manual installation

Install manually if react-native link failed - link

3. Final step

Open android/build.gradle and change minSdkVersion to 17.

Scope

The purpose of this module is to support most of the native image filters on each platform and to provide a common interface for these filters. If the filter exists only on one platform, then its counterpart will be implemented using renderscript on Android and cikernel on iOS. If you need only color matrix filters - better use a lightweight predecessor of this module.

Example

import { Image } from 'react-native'; import {   SoftLightBlend,   Emboss,   Earlybird,   Invert,   RadialGradient } from 'react-native-image-filter-kit';  const result = (   <Earlybird     image={       <SoftLightBlend         resizeCanvasTo={'dstImage'}         dstTransform={{           scale: 'CONTAIN'         }}         dstImage={           <Emboss             image={               <Image                 style={{ width: 320, height: 320 }}                 source={require('./parrot.png')}                 resizeMode={'contain'}               />             }           />         }         srcTransform={{           anchor: { x: 0.5, y: 1 },           translate: { x: 0.5, y: 1 }         }}         srcImage={           <Invert             image={               <RadialGradient                 colors={['rgba(0, 0, 255, 1)', '#00ff00', 'red']}                 stops={[0.25, 0.75, 1]}                 center={{ x: '50w', y: '100h' }}               />             }           />         }       />     }   /> )
original image result
 
filter steps
original image
Emboss
SoftLightBlend
Earlybird
RadialGradient
Invert

Reference

Caveats

  • blurRadius Image prop will not work in conjunction with this library, instead of it just use BoxBlur filter
  • When running on pre-Lollipop (SDK < 21) Android devices you may experience TooManyBitmapsException, which results in image is not being rendered (this can be logged with onFilteringError prop). It looks like this is a relatively rare case which arises on low-end devices when filtering wallpaper-sized images (like 1920 × 1080 pixels). The common workarounds are:
    • using smaller images
    • using ColorMatrix filter with concatColorMatrices instead of wrapping the image with multiple color matrix based filters
    • adding android:largeHeap="true" to android/app/src/main/AndroidManifest.xml
    • replacing standard MainReactPackage with alternative one provided by this module:
        ... - import com.facebook.react.shell.MainReactPackage; + import iyegoroff.imagefilterkit.MainReactPackageWithFrescoCache;   import com.facebook.soloader.SoLoader;    import java.util.Arrays;   import java.util.List;    public class MainApplication extends Application implements ReactApplication {  +   private class MainReactPackage extends MainReactPackageWithFrescoCache {}   ...
      After this change ImageFilter will not throw TooManyBitmapsException immediately and will clear Fresco image caches, trim bitmap pool memory and try to filter the image again several times until succeed or reach the limit of retries, specified by clearCachesMaxRetries prop.
  • If you are using react-native-asset - switch to iyegoroff/react-native-asset#with-key. In order to prevent unlinking of .cikernel files provided by react-native-image-filter-kit use react-native-asset the following way: npx iyegoroff/react-native-asset#with-key -a YOUR-OWN-ASSETS -k YOUR-APP-ID

Credits


You May Also Like