-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
No response (success nor error) with HEIC format. #59
Comments
I have same problem. |
I believe it might have something to do with these two lines in the library react-image-file-resizer/src/index.js Line 95 in 8a979bc
react-image-file-resizer/src/index.js Line 169 in 8a979bc
As I have looked into this further it is also due to the fact that pretty much no browser apart from Safari supports HEIC as a valid image format (so if you are using Chromium based browsers the fix I mention below wont work). If you are not on safari it looks like you would need some other method for converting from HEIC to something like png, jpeg, or webp first before resizing. Possible Solution (For Browsers which support HEIC)I believe I came up with a solution which fixes this problem, which not only applies to heic files but any other image file which is not a png, jpeg, or webp (such as svg). Change line 95 to be: Then line 169 to be: And it should now be able to handle any file which has a mime type like I made these changes to my local version of the library and it is now working with file types like heic and svg. I am not sure what other impacts this might have or what errors may come of this but I think the changes I mentioned are worth looking into. |
Hey @onurzorluer - any chance of incorporating this suggested fix? Would be nice to support heic in this great simple-to-use lib. |
This has become less urgent for me, as I forgot that when you don't explicitly accept |
I have also a workaround, which is very easy to use. Using the heic2any script: https://www.npmjs.com/package/heic2any Before running the resizer check the image type and convert:
|
Can you explain what you mean by this? I don't get it. iOS on phones converts HEIC to JPEG on the fly? that doesn't make sense |
When I try to resize the result of this I get the same error as the original Post on here. Do you do anything specific afterwards? |
Asking for help and telling someone their comment "doesn't make sense" isn't always the best strategy ;-). Anyway, I don't have the code at hand but if you search around you will see there are various scenarios where iOS devices will automatically convert HEIC to JPG if it's for image requests that do not accept HEIC. For example comments like the one below. I can't remember in the context of this component, but I had a similar experience from memory. For my use cases, this was enough. There may still be valid reasons others want to do it explicitly, however.
|
You're right. sorry wasn't in the best headspace yesterday. thanks for calling my attitude out and quick response/tip to help me resolve this. The solution that seems to work is specifically defining accept image file types to png jpeg, example below. const {
...
acceptedFiles,
} = useDropzone({
accept: {
"image/jpeg": [],
"image/png": [],
}
});
just tested and seems to work on mobile iphones well. if the desire is to add ability for people to upload HEIC images from desktop, then something like Cheers! |
Hello, I am running into problems with compressing a .heic image. It seems that all other image formats work perfectly, but when I use a .heic image, I do not get a response - neither a success or error in my catch.
I guess my question is, I don't seem to find anywhere how to specifically reject the returned promise from the 'resizeFile' method from the Resizer.imageFileResizer() method, how can I do that? Does this package even support heic (I cant find anything online about .heic files relating to this package at all -- curious).
This is my resizeFile method:
const resizeFile = (file: File) => {
return new Promise((resolve) => {
Resizer.imageFileResizer(
file,
1080,
1080,
'JPEG',
80,
0,
(uri) => {
resolve(uri);
},
'base64',
);
});
};
And this is my try catch which I am calling it from:
files.forEach(async (file, i) => {
try {
const image = await resizeFile(file);
const newFile = dataURIToBlob(image);
formData.append(file.name, newFile);
} catch (err) {
console.log(err);
}
});
Expected behavior
I expect a response, either an error or success from passing any type of image.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: