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

TypeError: undefined is not an object (evaluating 'ImageResizerAndroid.createResizedImage') in Expo App #89

Closed
maximilian-lindsey opened this issue Jul 12, 2017 · 7 comments

Comments

@maximilian-lindsey
Copy link

Hi,

I just tried to use ImageResizer like this in my Expo App on my Moto G4 running Android 7.0 and everytime I try to access the createResizedImage() mehtod I get this error

TypeError: undefined is not an object (evaluating 'ImageResizerAndroid.createResizedImage')

When I log ImageResizer I can see the method, but can't access it.
I used

npm install --save react-native-image-resizer
react-native link react-native-image-resizer

to install it.

This is the code of my project:

import React from 'react';
import React from 'react';
import { Button, Image, View } from 'react-native';
import { ImagePicker } from 'expo';
import ImageResizer from 'react-native-image-resizer';

export default class ImagePickerExample extends React.Component {

  state = {
    image: null,
  };

  render() {
    let { image } = this.state;
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Button
      title="Take an image"
      onPress={this._takeImage}
      />
      {image &&
        <Image source={{ uri: image }} style={{ width: 200, height: 200 }} />}
        </View>
        );
  }

  _takeImage = async () => {
    let result = await ImagePicker.launchCameraAsync({
      allowsEditing: false,
      quality: 0.7
    });
    
    if (!result.cancelled) {
      console.log(result.uri);
      // IMAGE RESIZER
      ImageResizer.createResizedImage(result.uri, 500, 500, 'JPEG', 70).then((resizedImageUri) => {
        console.log(resizedImageUri);
        result.uri = resizedImageUri;
        const photo = {
          uri: result.uri,
          type: 'image/jpeg',
          name: 'photo.jpg',
        }
        let body = new FormData();
        body.append('image', photo);
        fetch('http://192.168.0.17:3000/images/', {
          method: 'POST',
          headers: {
            'Accept': 'application/json',
            'Content-Type': 'multipart/form-data'
          },
          body: body
        })
        .then((response) => {
          console.log(JSON.stringify(response));
        })
        .catch((error) => {
          console.error(error);
        });
      }).catch((err) => {
        console.log(err);
      });     
    }
    this.setState({ image: result.uri });
  };
}

Here are my package.json dependencies:
"dependencies": { "expo": "^18.0.4", "react": "16.0.0-alpha.12", "react-native": "https://github.com/expo/react-native/archive/sdk-18.0.1.tar.gz", "react-native-image-resizer": "^0.1.1" }

Maybe you can help me fix this issue

@maximilian-lindsey
Copy link
Author

I tried to use ImageResizer in my Expo project because it is marked as usable on https://www.native.directory

@4ian
Copy link
Contributor

4ian commented Jul 13, 2017

Thanks for reporting the error! We're relying on Java and Objective-C native modules so yes that won't work in Expo, unless it's integrated in their SDK :)

@daominhsangvn
Copy link

You guys must detach the app before use module out of scope Expo

@4ian
Copy link
Contributor

4ian commented Aug 3, 2017

You must indeed eject. I'm closing this as https://www.native.directory/ now properly list the module as not being compatible with Expo :)

@4ian 4ian closed this as completed Aug 3, 2017
@Yamilquery
Copy link

So sad... 👎

@takotab
Copy link

takotab commented May 30, 2019

Any other options to change the size of a picture in expo?

@ahmedsmae
Copy link

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

6 participants