Skip to content

Commit

Permalink
Thumbnail generation allows both width and height as params
Browse files Browse the repository at this point in the history
  • Loading branch information
PrafulB committed Jan 9, 2024
1 parent 32b7cb0 commit 1da19ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 10 additions & 4 deletions imagebox3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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,
Expand Down
14 changes: 10 additions & 4 deletions imagebox3.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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,
Expand Down

0 comments on commit 1da19ab

Please sign in to comment.