Enhance article photo handling and API documentation.
- Updated API documentation to reflect changes in article data structure. - Improved ArticlePhoto component to support dynamic sizing and object fit options. - Added performance logging for image upload in ArticlePhotosDialog and ArticlePhotoTile components. - Enhanced ArticleTile to conditionally render photos and adjusted styling for better layout. - Optimized image preparation process with configurable AVIF encoding speed.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
const MAX_EDGE = 1000;
|
||||
const AVIF_MIME = 'image/avif';
|
||||
const AVIF_QUALITY = 80;
|
||||
/** libaom speed 0–10; higher = faster encode, slightly larger files. Bench: s10 ~8× vs s6, +5% bytes. */
|
||||
const AVIF_SPEED = 9;
|
||||
|
||||
let encodeAvif;
|
||||
let resizeImage;
|
||||
@@ -61,21 +63,48 @@ export async function prepareArticlePhoto(input) {
|
||||
throw new Error('Kein Bild.');
|
||||
}
|
||||
|
||||
const started = performance.now();
|
||||
|
||||
const decodeStarted = performance.now();
|
||||
const originalImageData = await decodeToImageData(input);
|
||||
const decodeMs = performance.now() - decodeStarted;
|
||||
|
||||
const { width, height } = scaledDimensions(
|
||||
originalImageData.width,
|
||||
originalImageData.height,
|
||||
);
|
||||
|
||||
const resizeStarted = performance.now();
|
||||
const resize = await getResizer();
|
||||
const imageData = await resize(originalImageData, { width, height });
|
||||
const resizeMs = performance.now() - resizeStarted;
|
||||
|
||||
const encodeStarted = performance.now();
|
||||
const encode = await getAvifEncoder();
|
||||
const avifBuffer = await encode(imageData, { quality: AVIF_QUALITY });
|
||||
const avifBuffer = await encode(imageData, {
|
||||
quality: AVIF_QUALITY,
|
||||
speed: AVIF_SPEED,
|
||||
});
|
||||
const encodeMs = performance.now() - encodeStarted;
|
||||
|
||||
const baseName = input instanceof File && input.name
|
||||
? input.name.replace(/\.[^.]+$/, '')
|
||||
: 'photo';
|
||||
|
||||
return new File([avifBuffer], `${baseName}.avif`, { type: AVIF_MIME });
|
||||
const file = new File([avifBuffer], `${baseName}.avif`, { type: AVIF_MIME });
|
||||
const totalMs = performance.now() - started;
|
||||
|
||||
console.log('[article-photo] process', {
|
||||
totalMs: Math.round(totalMs),
|
||||
decodeMs: Math.round(decodeMs),
|
||||
resizeMs: Math.round(resizeMs),
|
||||
encodeMs: Math.round(encodeMs),
|
||||
quality: AVIF_QUALITY,
|
||||
speed: AVIF_SPEED,
|
||||
inputBytes: input.size,
|
||||
outputBytes: file.size,
|
||||
size: `${width}×${height}`,
|
||||
});
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user