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

Invalid imageTag error from ImageStore.getBase64ForTag #12114

Closed
perrosnk opened this issue Jan 30, 2017 · 1 comment
Closed

Invalid imageTag error from ImageStore.getBase64ForTag #12114

perrosnk opened this issue Jan 30, 2017 · 1 comment
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@perrosnk
Copy link

Description

I am trying to get a base64 image from facebook profile picture.

  getImageFromFacebook() {
    const imageURL = this.props.userInfo.picture;
    Image.getSize(imageURL, (width, height) => {
      var imageSize = {width, height};
      ImageEditor.cropImage(imageURL, imageSize, (imageURI) => {
        console.log(imageURI);
        ImageStore.getBase64ForTag(imageURI, (base64Data) => {
          this.setState({pictureBase64: base64Data});
          ImageStore.removeImageForTag(imageURI);
        }, (reason) => console.log(reason) )
      }, (reason) => console.log(reason) )
    }, (reason) => console.log(reason))
  }

I am following the steps described in this #1158:

  1. Use Image.getSize(uri) to get the image dimensions.

  2. Use ImageEditor.cropImage(uri, cropData) to store a copy of the image in the ImageStore (if you pass the width and height you got in step 1) then cropImage won't actually crop the image, although it may still make a copy of it.

  3. Use ImageStore.getBase64ForTag(uri) to get the base64 data of the new image (pass the uri you got from the cropImage function, not the original).

  4. Don't forget to call ImageStore.removeImageForTag(uri) once you're done to delete the copy.

Although the ImageEditor.cropImage returns a valid URI (rct-image-store://0), ImageStore.getBase64ForTag fails with a reason:

code: "ERCTERRORDOMAIN0",
domain: "RCTErrorDomain",
message: "Invalid imageTag: rct-image-store://0"

Is this a bug or am I doing something wrong?

Additional Information

  • React Native version: 0.38
  • Platform: iOS
  • Operating System: MacOS
@perrosnk
Copy link
Author

It was my fault!

imageSize should be set like this:

      var imageSize = {
        size: {
          width,
          height
        },
        offset: {
          x: 0,
          y: 0,
        },
      };

If anyone else is interested, have a look here (https://github.com/facebook/react-native/blob/master/Libraries/Image/ImageEditor.js) for more options in cropping. Unfortunately the documentation is not that good yet.

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

2 participants