From f9a4cc42fdd3d91a14f69e3469104294594e18f5 Mon Sep 17 00:00:00 2001 From: ephraimduncan Date: Tue, 11 Aug 2026 15:37:40 +0000 Subject: [PATCH] fix: scale signature images to fill signature fields The field renderer decreased large signature images to the field size, but it did not increase small images. Thus a low-resolution image, for example an upload from a different tool, showed at its native pixel size and was too small. This change removes the cap on the scale factor in the Konva field renderer and in the v1 and legacy PDF insert paths. The image scales in the two directions to fill the field, and the aspect ratio stays the same. --- packages/lib/server-only/pdf/insert-field-in-pdf-v1.ts | 2 +- packages/lib/server-only/pdf/legacy-insert-field-in-pdf.ts | 2 +- packages/lib/universal/field-renderer/render-signature-field.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/lib/server-only/pdf/insert-field-in-pdf-v1.ts b/packages/lib/server-only/pdf/insert-field-in-pdf-v1.ts index db71e2f97..7bddb1657 100644 --- a/packages/lib/server-only/pdf/insert-field-in-pdf-v1.ts +++ b/packages/lib/server-only/pdf/insert-field-in-pdf-v1.ts @@ -135,7 +135,7 @@ export const insertFieldInPDFV1 = async (pdf: PDFDocument, field: FieldWithSigna let imageWidth = image.width; let imageHeight = image.height; - const scalingFactor = Math.min(fieldWidth / imageWidth, fieldHeight / imageHeight, 1); + const scalingFactor = Math.min(fieldWidth / imageWidth, fieldHeight / imageHeight); imageWidth = imageWidth * scalingFactor; imageHeight = imageHeight * scalingFactor; diff --git a/packages/lib/server-only/pdf/legacy-insert-field-in-pdf.ts b/packages/lib/server-only/pdf/legacy-insert-field-in-pdf.ts index fdd5515e8..7663d1bb4 100644 --- a/packages/lib/server-only/pdf/legacy-insert-field-in-pdf.ts +++ b/packages/lib/server-only/pdf/legacy-insert-field-in-pdf.ts @@ -128,7 +128,7 @@ export const legacy_insertFieldInPDF = async (pdf: PDFDocument, field: FieldWith let imageWidth = image.width; let imageHeight = image.height; - const scalingFactor = Math.min(fieldWidth / imageWidth, fieldHeight / imageHeight, 1); + const scalingFactor = Math.min(fieldWidth / imageWidth, fieldHeight / imageHeight); imageWidth = imageWidth * scalingFactor; imageHeight = imageHeight * scalingFactor; diff --git a/packages/lib/universal/field-renderer/render-signature-field.ts b/packages/lib/universal/field-renderer/render-signature-field.ts index a43d46115..4888f9a70 100644 --- a/packages/lib/universal/field-renderer/render-signature-field.ts +++ b/packages/lib/universal/field-renderer/render-signature-field.ts @@ -23,7 +23,7 @@ const getImageDimensions = (img: HTMLImageElement, fieldWidth: number, fieldHeig let imageWidth = img.width; let imageHeight = img.height; - const scalingFactor = Math.min(fieldWidth / imageWidth, fieldHeight / imageHeight, 1); + const scalingFactor = Math.min(fieldWidth / imageWidth, fieldHeight / imageHeight); imageWidth = imageWidth * scalingFactor; imageHeight = imageHeight * scalingFactor;