fix: normalize vip98k references for provider limits
This commit is contained in:
parent
d133a48866
commit
0a364f537f
@ -644,20 +644,14 @@ async function downloadReferenceImageFromStorage(
|
||||
|
||||
async function normalizeReferenceImage(buffer: Buffer, mimeType: string) {
|
||||
try {
|
||||
const metadata = await sharp(buffer, { failOn: "none" }).metadata();
|
||||
const pipeline = sharp(buffer, { failOn: "none" })
|
||||
const normalized = await sharp(buffer, { failOn: "none" })
|
||||
.rotate()
|
||||
.resize(2048, 2048, { fit: "inside", withoutEnlargement: true });
|
||||
if (metadata.hasAlpha || /png/i.test(mimeType)) {
|
||||
.resize(1920, 1920, { fit: "inside", withoutEnlargement: true })
|
||||
.flatten({ background: "#ffffff" })
|
||||
.jpeg({ quality: 92, chromaSubsampling: "4:4:4", mozjpeg: true })
|
||||
.toBuffer();
|
||||
return {
|
||||
buffer: await pipeline.png({ compressionLevel: 6 }).toBuffer(),
|
||||
extension: "png",
|
||||
};
|
||||
}
|
||||
return {
|
||||
buffer: await pipeline
|
||||
.jpeg({ quality: 95, chromaSubsampling: "4:4:4", mozjpeg: true })
|
||||
.toBuffer(),
|
||||
buffer: normalized,
|
||||
extension: "jpg",
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user