Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting images with cssgram filters + color matrix filters #148

Open
sberkeo opened this issue Mar 27, 2024 · 1 comment
Open

Extracting images with cssgram filters + color matrix filters #148

sberkeo opened this issue Mar 27, 2024 · 1 comment

Comments

@sberkeo
Copy link

sberkeo commented Mar 27, 2024

I could not fully understand the documentation and achieve success. cssgram filters are running successfully and being extracted. For the color matrix, I change values such as brightness and contrast in the image with the @react-native-color-matrix-image-filters library. It was successful in the preview, but when I tried to extract the image with the @react-native-image-filter-kit library, it ignored the color matrix. I decided to completely switch back to concatcolorMatrix in @react-native-image-filter-kit, but this time I'm getting an error. [Invariant Violation: Color matrix matB should be an array with 20 elements.]. I would be very happy if anyone could show me the right way. I need to make changes to cssgram filters and color matrix and extract the image.

import {
    AdenCompat,
    _1977Compat,
    BrannanCompat,
    BrooklynCompat,
    ClarendonCompat,
    EarlybirdCompat,
    GinghamCompat,
    HudsonCompat,
    InkwellCompat,
    KelvinCompat,
    LarkCompat,
    LofiCompat,
    MavenCompat,
    MayfairCompat,
    MoonCompat,
    NashvilleCompat,
    PerpetuaCompat,
    ReyesCompat,
    RiseCompat,
    SlumberCompat,
    StinsonCompat,
    ToasterCompat,
    ValenciaCompat,
    WaldenCompat,
    WillowCompat,
    Xpro2Compat,
    OverlayBlend,
    saturate,
    tint,
    concatColorMatrices,
    ColorMatrix,
    brightness,
    contrast,
    temperature,
    hueRotate,
    grayscale,
    sepia,
} from 'react-native-image-filter-kit';
const FILTERS = [
    {
        title: 'Normal',
        filterComponent: AdenCompat,
    },
    {
        title: 'Maven',
        filterComponent: MavenCompat,
    },
    {
        title: 'Mayfair',
        filterComponent: MayfairCompat,
    },
    {
        title: 'Moon',
        filterComponent: MoonCompat,
    },
    {
        title: 'Nashville',
        filterComponent: NashvilleCompat,
    },
    {
        title: 'Perpetua',
        filterComponent: PerpetuaCompat,
    },
    {
        title: 'Reyes',
        filterComponent: ReyesCompat,
    },
    {
        title: 'Rise',
        filterComponent: RiseCompat,
    },
    {
        title: 'Slumber',
        filterComponent: SlumberCompat,
    },
    {
        title: 'Stinson',
        filterComponent: StinsonCompat,
    },
    {
        title: 'Brooklyn',
        filterComponent: BrooklynCompat,
    },
    {
        title: 'Earlybird',
        filterComponent: EarlybirdCompat,
    },
    {
        title: 'Clarendon',
        filterComponent: ClarendonCompat,
    },
    {
        title: 'Gingham',
        filterComponent: GinghamCompat,
    },
    {
        title: 'Hudson',
        filterComponent: HudsonCompat,
    },
    {
        title: 'Inkwell',
        filterComponent: InkwellCompat,
    },
    {
        title: 'Kelvin',
        filterComponent: KelvinCompat,
    },
    {
        title: 'Lark',
        filterComponent: LarkCompat,
    },
    {
        title: 'Lofi',
        filterComponent: LofiCompat,
    },
    {
        title: 'Toaster',
        filterComponent: ToasterCompat,
    },
    {
        title: 'Valencia',
        filterComponent: ValenciaCompat,
    },
    {
        title: 'Walden',
        filterComponent: WaldenCompat,
    },
    {
        title: 'Willow',
        filterComponent: WillowCompat,
    },
    {
        title: 'Xpro2',
        filterComponent: Xpro2Compat,
    },
    {
        title: 'Aden',
        filterComponent: AdenCompat,
    },
    {
        title: '_1977',
        filterComponent: _1977Compat,
    },
    {
        title: 'Brannan',
        filterComponent: BrannanCompat,
    },
];

const SelectedFilterComponent = FILTERS[selectedFilterIndex].filterComponent;

<SelectedFilterComponent
     //onExtractImage={onExtractImage}
      style={{ backgroundColor: 'transparent', width: windowWidth / 1.2, zIndex: 1122 }}
      onExtractImage={onExtractFilter}
      extractImageEnabled={filterextracter}
            image={
                <View style={{ borderRadius: 15, overflow: 'hidden', backgroundColor: 'transparent' }}>
                   <ColorMatrix matrix={concatColorMatrices(
                        brightness(CMfilterValues.brightness / 50)
                         , contrast(CMfilterValues.contrast / 50)
                         , temperature((CMfilterValues.temperature - 50) / 50)
                         , saturate((((CMfilterValues.saturation + 20) - 50) / 50))
                         , hueRotate((CMfilterValues.hueRotate - 50) / 50)
                         , grayscale(CMfilterValues.grayscale / 50)
                         , sepia(CMfilterValues.sepia / 50)
                         , tint(CMfilterValues.tint / 50)

                     )}>

                         <Image
                             ref={editPhotoRef}
                             style={{ aspectRatio: 1, backgroundColor: 'transparent' }}
                             source={{ uri: 'file://' + editPhoto.path }}
                             resizeMode={editPhotoScreenMode}
                             />



                    </ColorMatrix>
                </View>
                }
 />

@iyegoroff @xzilja @kaidoj @TrebuhD @HarshitMadhav

@shahmeer-ali
Copy link

@sberkeo hey there,
the onExtractImage should be under the ColorMatrix

like this:

<ColorMatrix
onExtractImage={({nativeEvent}) => {
console.info('onExtractImage', nativeEvent);
setFilterImageURI(nativeEvent.uri);
}}

and then on event filter event, it will generate a temp file, you can log like this
LOG onExtractImage {"uri": "file:///data/user/0/com.propershot/cache/tmp3659330855580970101.rnifk.png"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants