wip
This commit is contained in:
parent
6205dc44f0
commit
785258da20
|
@ -7,30 +7,23 @@ import isAnimated from 'is-file-animated';
|
||||||
import { isWebpSupported } from './isWebpSupported.js';
|
import { isWebpSupported } from './isWebpSupported.js';
|
||||||
import type { BrowserImageResizerConfigWithConvertedOutput } from '@misskey-dev/browser-image-resizer';
|
import type { BrowserImageResizerConfigWithConvertedOutput } from '@misskey-dev/browser-image-resizer';
|
||||||
|
|
||||||
const compressTypeMap = {
|
const supportedTypes = [
|
||||||
'image/jpeg': { quality: 0.85, mimeType: 'image/webp' },
|
'image/jpeg',
|
||||||
'image/png': { quality: 1, mimeType: 'image/webp' },
|
'image/png',
|
||||||
'image/webp': { quality: 0.85, mimeType: 'image/webp' },
|
'image/webp',
|
||||||
'image/svg+xml': { quality: 1, mimeType: 'image/webp' },
|
'image/svg+xml',
|
||||||
} as const;
|
] as const;
|
||||||
|
|
||||||
const compressTypeMapFallback = {
|
|
||||||
'image/jpeg': { quality: 0.8, mimeType: 'image/jpeg' },
|
|
||||||
'image/png': { quality: 1, mimeType: 'image/png' },
|
|
||||||
'image/webp': { quality: 0.8, mimeType: 'image/jpeg' },
|
|
||||||
'image/svg+xml': { quality: 1, mimeType: 'image/png' },
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export async function getCompressionConfig(file: File, options: Partial<{ maxWidth: number; maxHeight: number; }> = {}): Promise<BrowserImageResizerConfigWithConvertedOutput | undefined> {
|
export async function getCompressionConfig(file: File, options: Partial<{ maxWidth: number; maxHeight: number; }> = {}): Promise<BrowserImageResizerConfigWithConvertedOutput | undefined> {
|
||||||
const imgConfig = (isWebpSupported() ? compressTypeMap : compressTypeMapFallback)[file.type];
|
if (!supportedTypes.includes(file.type) || await isAnimated(file)) {
|
||||||
if (!imgConfig || await isAnimated(file)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
mimeType: isWebpSupported() ? 'image/webp' : 'image/jpeg',
|
||||||
maxWidth: options.maxWidth ?? 2048,
|
maxWidth: options.maxWidth ?? 2048,
|
||||||
maxHeight: options.maxHeight ?? 2048,
|
maxHeight: options.maxHeight ?? 2048,
|
||||||
|
quality: isWebpSupported() ? 0.9 : 0.85,
|
||||||
debug: true,
|
debug: true,
|
||||||
...imgConfig,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue