mirror of
https://github.com/documenso/documenso.git
synced 2026-08-15 02:53:32 +10:00
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.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user