From 1da19abc135aa5bfeebc2eb88525689a0a3329e3 Mon Sep 17 00:00:00 2001 From: Praful Bhawsar Date: Tue, 9 Jan 2024 16:49:36 -0500 Subject: [PATCH] Thumbnail generation allows both width and height as params --- imagebox3.js | 14 ++++++++++---- imagebox3.mjs | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/imagebox3.js b/imagebox3.js index 16bd80b..f77e504 100644 --- a/imagebox3.js +++ b/imagebox3.js @@ -254,9 +254,9 @@ var imagebox3 = (() => { const parsedTileParams = utils.parseTileParams(tileParams) - const { thumbnailWidthToRender } = parsedTileParams - if (!Number.isInteger(thumbnailWidthToRender)) { - console.error("Thumbnail Request missing critical parameters!", thumbnailWidthToRender) + let { thumbnailWidthToRender, thumbnailHeightToRender } = parsedTileParams + if (!Number.isInteger(thumbnailWidthToRender) && !Number.isInteger(thumbnailHeightToRender)) { + console.error("Thumbnail Request missing critical parameters!", thumbnailWidthToRender, thumbnailHeightToRender) return } @@ -265,7 +265,13 @@ var imagebox3 = (() => { } const thumbnailImage = await tiff[imageID].pyramid.getImage(1) - const thumbnailHeightToRender = Math.floor(thumbnailImage.getHeight() * thumbnailWidthToRender / thumbnailImage.getWidth()) + + if (thumbnailWidthToRender && !thumbnailHeightToRender) { + thumbnailHeightToRender = Math.floor(thumbnailImage.getHeight() * thumbnailWidthToRender / thumbnailImage.getWidth()) + } + else if (thumbnailHeightToRender && !thumbnailWidthToRender) { + thumbnailWidthToRender = Math.floor(thumbnailImage.getHeight() * thumbnailHeightToRender / thumbnailImage.getWidth()) + } let data = await thumbnailImage.readRasters({ width: thumbnailWidthToRender, diff --git a/imagebox3.mjs b/imagebox3.mjs index 2be51cf..c115f79 100644 --- a/imagebox3.mjs +++ b/imagebox3.mjs @@ -233,9 +233,9 @@ const imagebox3 = (() => { const parsedTileParams = utils.parseTileParams(tileParams) - const { thumbnailWidthToRender } = parsedTileParams - if (!Number.isInteger(thumbnailWidthToRender)) { - console.error("Thumbnail Request missing critical parameters!", thumbnailWidthToRender) + let { thumbnailWidthToRender, thumbnailHeightToRender } = parsedTileParams + if (!Number.isInteger(thumbnailWidthToRender) && !Number.isInteger(thumbnailHeightToRender)) { + console.error("Thumbnail Request missing critical parameters!", thumbnailWidthToRender, thumbnailHeightToRender) return } @@ -244,7 +244,13 @@ const imagebox3 = (() => { } const thumbnailImage = await tiff[imageID].pyramid.getImage(1) - const thumbnailHeightToRender = Math.floor(thumbnailImage.getHeight() * thumbnailWidthToRender / thumbnailImage.getWidth()) + + if (!thumbnailHeightToRender) { + thumbnailHeightToRender = Math.floor(thumbnailImage.getHeight() * thumbnailWidthToRender / thumbnailImage.getWidth()) + } + else if (!thumbnailWidthToRender) { + thumbnailWidthToRender = Math.floor(thumbnailImage.getHeight() * thumbnailHeightToRender / thumbnailImage.getWidth()) + } let data = await thumbnailImage.readRasters({ width: thumbnailWidthToRender,