diff --git a/lib/canvas/generate-image.ts b/lib/canvas/generate-image.ts index 69cf75b96..33700518e 100644 --- a/lib/canvas/generate-image.ts +++ b/lib/canvas/generate-image.ts @@ -361,18 +361,21 @@ async function getScaleAdjustRegionSample(params: { sourceHeight: number; region: CanvasLocalEditCompositeRegion; }) { + const normalizedBuffer = await sharp(params.buffer, { failOn: "none" }) + .rotate() + .resize(params.sourceWidth, params.sourceHeight, { + fit: "cover", + position: "center", + }) + .png({ compressionLevel: 6 }) + .toBuffer(); const box = rectToPixelBox({ region: params.region, width: params.sourceWidth, height: params.sourceHeight, }); - return sharp(params.buffer, { failOn: "none" }) - .rotate() - .resize(params.sourceWidth, params.sourceHeight, { - fit: "cover", - position: "center", - }) + return sharp(normalizedBuffer, { failOn: "none" }) .extract(box) .resize(SCALE_ADJUST_DIFF_SAMPLE_SIZE, SCALE_ADJUST_DIFF_SAMPLE_SIZE, { fit: "fill",