Skip to content
Snippets Groups Projects
Commit 45560ab1 authored by Chris Beer's avatar Chris Beer
Browse files

Refactor out thumbnailConstraints helper

parent 7808c469
No related branches found
No related tags found
No related merge requests found
......@@ -51,31 +51,35 @@ export default class ManifestoCanvas {
return undefined;
}
if (maxWidth && maxHeight) {
const { aspectRatio } = this;
const desiredAspectRatio = maxWidth / maxHeight;
// size to width
if (desiredAspectRatio < aspectRatio) {
height = null;
width = maxWidth;
} else {
switch (this.thumbnailConstraints(maxWidth, maxHeight)) {
case 'sizeByH':
height = maxHeight;
width = null;
}
} else if (!maxWidth && !maxHeight) {
width = null;
height = '150';
} else {
break;
case 'sizeByW':
width = maxWidth;
height = maxHeight;
break;
default:
height = '150';
}
// note that, although the IIIF server may support sizeByConfinedWh (e.g. !w,h)
// this is a IIIF level 2 feature, so we're instead providing w, or h,-style requests
// which are only level 1.
return this.canonicalImageUri.replace(/\/full\/.*\/0\//, `/full/${width || ''},${height || ''}/0/`);
}
/** @private */
thumbnailConstraints(maxWidth, maxHeight) {
if (!maxHeight && !maxWidth) return undefined;
if (maxHeight && !maxWidth) return 'sizeByH';
if (!maxHeight && maxWidth) return 'sizeByW';
const { aspectRatio } = this;
const desiredAspectRatio = maxWidth / maxHeight;
return desiredAspectRatio < aspectRatio ? 'sizeByW' : 'sizeByH';
}
/**
* checks whether the canvas has a valid height
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment