My server doesn't support the HEIF format. So I need to transform it to JPEG before uploading from my app.
I do this:
UIImage *image = [UIImage imageWithData:imageData];
NSData *data=UIImageJPEGRepresentation(image, 1.0);
But how can I know that the data is HEIF (or HEIC) ? I can look at a file:
([filePath hasSuffix:@".HEIC"] || [filePath hasSuffix:@".heic"])
But I don't think it's a good answer. Is there any other solution?
HEIC files are the default format for images across your Apple devices, so it should be easy to open them on your Mac. Just right-click on the file and select Open with Preview – the file should then launch in the Preview program. Alternatively, you can import the files to your Photos app or upload them to Dropbox.
The most likely culprit: Your photo was saved as an HEIC file, Apple's own image format, that is not JPEG. Apple committed to HEIC back in 2017 with iOS 11 as a way to save storage space as the iPhone camera system improved.
Install "HEIF Image Extensions" from the Microsoft Store to open HEIC files. You can convert an HEIC file to a JPG on Windows using CopyTrans or an online converter. Programs like Photoshop and GIMP can also open HEIC files. Apple's iPhone and iPad take photos in the HEIF image format by default.
HEIF is the name for the standard — High Efficiency Image Format — while HEIC is Apple's chosen file name extension. The terms are basically interchangeable because the High Efficiency Video Compression (HEVC) standard, also known as H. 265, is the base for both.
A bit late to the party, but other than checking the extension (after the last dot), you can also check for the "magic number" aka file signature. Byte 5 to 8 should give you the constant "ftyp". The following 4 bytes would be the major brand, which I believe is one of "mif1", "heic" and "heix". For example, the first 12 bytes of a .heic image would be:
00 00 00 18 66 74 79 70 6d 69 66 31
which, after removing 0s and trim the result, literally decoded to ftypmif1
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With