Skip to content

Commit

Permalink
mobile: convert heic/heif images to jpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarahm-ed committed May 20, 2024
1 parent 73ec04b commit adf0f13
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 4 additions & 3 deletions apps/mobile/app/screens/editor/tiptap/picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ const camera = async (options: PickerOptions) => {
cropping: false,
multiple: true,
maxFiles: 10,
writeTempFile: true
writeTempFile: true,
compressImageQuality: 1
})
.then((response) => {
handleImageResponse(
Expand Down Expand Up @@ -215,7 +216,8 @@ const gallery = async (options: PickerOptions) => {
mediaType: "photo",
maxFiles: 10,
cropping: false,
multiple: true
multiple: true,
compressImageQuality: 1
})
.then((response) =>
handleImageResponse(
Expand Down Expand Up @@ -266,7 +268,6 @@ const handleImageResponse = async (
response: Image[],
options: PickerOptions
) => {
console.log(response, "result-file-picker");
const result = await AttachImage.present(response, options.context);
if (!result) return;
const compress = result.compress;
Expand Down
16 changes: 16 additions & 0 deletions apps/mobile/patches/react-native-image-crop-picker+0.40.2.patch
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,19 @@ index 5de0845..1b158d8 100644

if (includeBase64) {
image.putString("data", getBase64StringFromFile(compressedImagePath));
diff --git a/node_modules/react-native-image-crop-picker/ios/src/ImageCropPicker.m b/node_modules/react-native-image-crop-picker/ios/src/ImageCropPicker.m
index 9f20973..5e14da8 100644
--- a/node_modules/react-native-image-crop-picker/ios/src/ImageCropPicker.m
+++ b/node_modules/react-native-image-crop-picker/ios/src/ImageCropPicker.m
@@ -595,8 +595,10 @@ - (void)qb_imagePickerController:
NSString *mimeType = [self determineMimeTypeFromImageData:imageData];
Boolean isKnownMimeType = [mimeType length] > 0;

+ Boolean isHeicOrHeif = [mimeType isEqualToString:@"image/heic"] || [mimeType isEqualToString:@"image/heif"];
+
ImageResult *imageResult = [[ImageResult alloc] init];
- if (isLossless && useOriginalWidth && useOriginalHeight && isKnownMimeType && !forceJpg) {
+ if (isLossless && useOriginalWidth && useOriginalHeight && isKnownMimeType && !forceJpg && !isHeicOrHeif) {
// Use original, unmodified image
imageResult.data = imageData;
imageResult.width = @(imgT.size.width);

0 comments on commit adf0f13

Please sign in to comment.