Converting heic/heif to jpg in react native (or nodejs)

1.4k views Asked by At

I have a react native app on ios where users can upload photos. I resize these photos server-side with sharp. The problem is: the HEIC/HEIF-files from ios are not compatible with sharp. I get the following error:

¡Error: source: bad seek to 2808991
heif: Unsupported feature: Unsupported codec (4.3000)
¿

Is there a way to get a JPG version of the photo? It's also ok if I have to convert the file to jpg on the server, but how can I detect the codec of the image (so that only HEIC/HEIF images are converted, and not jpg or png)?

How can I convert them client side or server side?

1

There are 1 answers

0
eeshankeni On

React Native Image Resizer can perform HEIC to jpeg compression on the app. It's a native module so you'll have to build a development client if you're using expo.