question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

decodeJpeg() function don't work in react native

See original GitHub issue

So I basically copy the same code from the doc (https://blog.tensorflow.org/2020/02/tensorflowjs-for-react-native-is-here.html) about using tensorflow in react native. However when I want to call decodeJpeg function it returns an error

Error: Expected image (JPEG, PNG, or GIF), but got unsupported image type getImageType@http://192.168.0.141:8081/index.bundle?platform=ios&dev=true&minify=false:377324:22

I tried different ways and don’t know if my setup is wrong or the doc is wrong Below is what I tried (1)

const response = await fetch(imageurl, {}, {isBinary: true});
    const imageData = await response.arrayBuffer();

    const img = decodeJpeg(imageData);

(2)

const img = decodeJpeg(imageurl)

the imageurl is from iPhone photo library so technically it’s not from online but I think they should work the same. Do I need to show more setup?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tafsiricommented, Jan 13, 2021

Could you try wrapping your arraybuffer in a UInt8Array similar to this example https://js.tensorflow.org/api_react_native/0.5.0/#decodeJpeg.

If that doesn’t work could you upload a sample image file that shows this behaviour.

0reactions
google-ml-butler[bot]commented, Jan 14, 2021

Are you satisfied with the resolution of your issue? Yes No

Read more comments on GitHub >

github_iconTop Results From Across the Web

can't find decodeJpeg from tfjs-react-native - Stack Overflow
i want to tensorflow-js with react-native so i read document. in there, write when image to tensor use decodeJpeg. but can't find decodeJpeg....
Read more >
Top 5 jpeg-js Code Examples - Snyk
Learn more about how to use jpeg-js, based on jpeg-js code examples created from the most popular ways it is used in public...
Read more >
Images - React Native
In React Native, image decoding is done in a different thread. In practice, you already need to handle the case when the image...
Read more >
Blob - The Modern JavaScript Tutorial
By default "transparent" (do nothing), but also can be "native" (transform). ... as the mapping is removed, the URL doesn't work any more....
Read more >
Picture perfect images with the modern <img> element
You may not think about images as part of your web dev work, ... like Next.js <Image> (for React) and Nuxt image (for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found