Option to send photos as high quality
This commit is contained in:
parent
6c56d5a5f1
commit
01eabf9ec6
44 changed files with 1263 additions and 363 deletions
31
ts/util/autoOrientImage.ts
Normal file
31
ts/util/autoOrientImage.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Copyright 2018-2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import loadImage, { LoadImageOptions } from 'blueimp-load-image';
|
||||
import { IMAGE_JPEG } from '../types/MIME';
|
||||
import { canvasToBlob } from './canvasToBlob';
|
||||
|
||||
const DEFAULT_JPEG_QUALITY = 0.85;
|
||||
|
||||
export async function autoOrientImage(blob: Blob): Promise<Blob> {
|
||||
const options: LoadImageOptions = {
|
||||
canvas: true,
|
||||
orientation: true,
|
||||
};
|
||||
|
||||
try {
|
||||
const data = await loadImage(blob, options);
|
||||
const { image } = data;
|
||||
if (image instanceof HTMLCanvasElement) {
|
||||
// We `return await`, instead of just `return`, so we capture the rejection in this
|
||||
// try/catch block. See [this blog post][0] for more background.
|
||||
// [0]: https://jakearchibald.com/2017/await-vs-return-vs-return-await/
|
||||
return await canvasToBlob(image, IMAGE_JPEG, DEFAULT_JPEG_QUALITY);
|
||||
}
|
||||
throw new Error('image not a canvas');
|
||||
} catch (err) {
|
||||
const error = new Error('autoOrientImage: Failed to process image');
|
||||
error.originalError = err;
|
||||
throw error;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue