Transcode all supported image types
This commit is contained in:
parent
a73d7b42cf
commit
ff67d9178b
2 changed files with 10 additions and 2 deletions
|
@ -6,7 +6,6 @@ const is = require('@sindresorhus/is');
|
||||||
const { arrayBufferToBlob, blobToArrayBuffer } = require('blob-util');
|
const { arrayBufferToBlob, blobToArrayBuffer } = require('blob-util');
|
||||||
const AttachmentTS = require('../../../ts/types/Attachment');
|
const AttachmentTS = require('../../../ts/types/Attachment');
|
||||||
const GoogleChrome = require('../../../ts/util/GoogleChrome');
|
const GoogleChrome = require('../../../ts/util/GoogleChrome');
|
||||||
const MIME = require('../../../ts/types/MIME');
|
|
||||||
const { toLogFormat } = require('./errors');
|
const { toLogFormat } = require('./errors');
|
||||||
const { scaleImageToLevel } = require('../../../ts/util/scaleImageToLevel');
|
const { scaleImageToLevel } = require('../../../ts/util/scaleImageToLevel');
|
||||||
const {
|
const {
|
||||||
|
@ -51,7 +50,7 @@ exports.isValid = rawAttachment => {
|
||||||
// NOTE: This step strips all EXIF metadata from JPEG images as
|
// NOTE: This step strips all EXIF metadata from JPEG images as
|
||||||
// part of re-encoding the image:
|
// part of re-encoding the image:
|
||||||
exports.autoOrientJPEG = async (attachment, _, message) => {
|
exports.autoOrientJPEG = async (attachment, _, message) => {
|
||||||
if (!MIME.isJPEG(attachment.contentType)) {
|
if (!AttachmentTS.canBeTranscoded(attachment)) {
|
||||||
return attachment;
|
return attachment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -181,6 +181,15 @@ export function isImageAttachment(
|
||||||
isImageTypeSupported(attachment.contentType)
|
isImageTypeSupported(attachment.contentType)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function canBeTranscoded(
|
||||||
|
attachment?: AttachmentType
|
||||||
|
): attachment is AttachmentType {
|
||||||
|
return Boolean(
|
||||||
|
isImageAttachment(attachment) && !MIME.isGif(attachment.contentType)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function hasImage(
|
export function hasImage(
|
||||||
attachments?: Array<AttachmentType>
|
attachments?: Array<AttachmentType>
|
||||||
): string | boolean | undefined {
|
): string | boolean | undefined {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue