bamlab / react-native-image-resizer

🗻 Resize local images with React Native
MIT License
1.6k stars 342 forks source link

[TypeError: null is not an object (evaluating 'ImageResizer.createResizedImage')] Unable to resize #353

Closed stivenm16 closed 1 year ago

stivenm16 commented 1 year ago

I'm getting this error when I tried to resize an img, I'm following docs but the error persists. Here the code:

const res = await ImageResizer.createResizedImage( uri, sizeTarget, sizeTarget, "JPEG", 80, 0, undefined ) .then((response) => { const { name, uri } = response; const base64 = FileSystem.readAsStringAsync(uri, EncodingType.Base64); return { name, base64 }; }) .catch((e) => { console.log(e); });

The App stops before encoding and throw [TypeError: null is not an object (evaluating 'ImageResizer.createResizedImage')] Unable to resize

I'm running my app on Android

hellocaio commented 1 year ago

I ran into this issue too, my problem was that I was using the wrong development client. I don't know if you are using a custom development client but if you are this might be the issue.

taboulot commented 1 year ago

Hi @stivenm16 ,

I tried to reproduce it in the example app and I have no problem:

// App.tsx
  const resize = async () => {
    if (!image || !image.uri) return;

    setResizedImage(null);

    try {
      let result = await ImageResizer.createResizedImage(
        image.uri,
        sizeTarget,
        sizeTarget,
        'JPEG',
        80,
        0,
        undefined
      );

      setResizedImage(result);
    } catch (error) {
      Alert.alert('Unable to resize the photo');
    }
  };

Did you find the issue? Do you have a reproducible example?

bpeck81 commented 1 year ago

I'm getting this error too..

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

This issue has been automatically closed. Thank you for your contributions.

luihugo commented 1 year ago

Am getting error as well

I'm getting this error too.. did you find a fix?

luihugo commented 1 year ago

@taboulot am also getting the error [TypeError: null is not an object (evaluating 'ImageResizer.createResizedImage')]

my uri is as file:///data/user/0/com.cashlet.development/cache/Camera/2ad1e650-c2ba-435f-bc3e-628cb67737e7.jpg

my usage const data = await camera.takePictureAsync(options); console.log(data.uri); if (data && data?.uri) { try { let result = await ImageResizer.createResizedImage( data?.uri, 80, 80, 'JPEG', 70, 0, undefined, false, { mode: 'contain', onlyScaleDown: true, }, ); console.log(result?.size, result.uri, 'image'); // addKYCUserDetails(result?.uri, 'idImage'); // this.setState({screen: 'retake'}); } catch (error: any) { console.log(error); Alert.alert(error); } } I also get the following error on the screen Screenshot_20230703_173912_com cashlet development

luihugo commented 1 year ago

I ran into this issue too, my problem was that I was using the wrong development client. I don't know if you are using a custom development client but if you are this might be the issue.

@caiogmar what do you mean custom development client?

luihugo commented 1 year ago

Got it! In my case I reinstalled nodemodules and rebuild my dev client again, I guess its an issue with linking