Skip to content

Commit

Permalink
Always convert HEIC images to JPEG.
Browse files Browse the repository at this point in the history
This pr changes the behavior of sending HEIC images to always convert
them to JPEG. This conversion is required to support image inline
viewing accross different devices and operating systems. This follows
the same strategy as on IOS: signalapp/Signal-iOS#2511

Fixes: signalapp/Signal-iOS#4374 & #9395
  • Loading branch information
bkchr authored and greyson-signal committed May 29, 2020
1 parent 11d17f7 commit 4712833
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Expand Up @@ -145,6 +145,10 @@ private void scaleAndStripExif(@NonNull AttachmentDatabase attachmentDatabase,
if (!constraints.isSatisfied(context, attachment)) {
throw new UndeliverableMessageException("Size constraints could not be met on video!");
}
} else if (MediaUtil.isHeic(attachment)) {
MediaStream converted = getResizedMedia(context, attachment, constraints);
attachmentDatabase.updateAttachmentData(attachment, converted, false);
attachmentDatabase.markAttachmentAsTransformed(attachmentId);
} else if (constraints.isSatisfied(context, attachment)) {
if (MediaUtil.isJpeg(attachment)) {
MediaStream stripped = getResizedMedia(context, attachment, constraints);
Expand Down
Expand Up @@ -49,6 +49,7 @@ public class MediaUtil {

public static final String IMAGE_PNG = "image/png";
public static final String IMAGE_JPEG = "image/jpeg";
public static final String IMAGE_HEIC = "image/heic";
public static final String IMAGE_WEBP = "image/webp";
public static final String IMAGE_GIF = "image/gif";
public static final String AUDIO_AAC = "audio/aac";
Expand Down Expand Up @@ -219,6 +220,10 @@ public static boolean isJpeg(Attachment attachment) {
return isJpegType(attachment.getContentType());
}

public static boolean isHeic(Attachment attachment) {
return isHeicType(attachment.getContentType());
}

public static boolean isImage(Attachment attachment) {
return isImageType(attachment.getContentType());
}
Expand Down Expand Up @@ -247,6 +252,10 @@ public static boolean isJpegType(String contentType) {
return !TextUtils.isEmpty(contentType) && contentType.trim().equals(IMAGE_JPEG);
}

public static boolean isHeicType(String contentType) {
return !TextUtils.isEmpty(contentType) && contentType.trim().equals(IMAGE_HEIC);
}

public static boolean isFile(Attachment attachment) {
return !isGif(attachment) && !isImage(attachment) && !isAudio(attachment) && !isVideo(attachment);
}
Expand Down

0 comments on commit 4712833

Please sign in to comment.