function createPanes() {
let panes = [];
let imageWidthPx = image.width;
let imageHeightPx = image.height;
let maxFrameDimensionPx = Math.max(widthPx - 2 * paddingPx, heightPx - 2 * paddingPx);
let minImageDimensionPx = Math.min(image.width, image.height);
let scale = maxFrameDimensionPx / minImageDimensionPx;
let newWidthPx = imageWidthPx * scale;
let newHeightPx = imageHeightPx * scale;
console.log(imageHeightPx, scale, newHeightPx);
if (imageWidthPx >= imageHeightPx) {
let count = Math.ceil((newWidthPx + 2 * paddingPx) / widthPx);
let offsetPx = (count * widthPx - newWidthPx) / 2;
for (let i = 0; i < count; i++) {
panes.push(drawImage(function(ctx) {
ctx.fillStyle = border;
ctx.fillRect(offsetPx - i * widthPx - borderPx, paddingPx - borderPx, newWidthPx + 2 * borderPx, newHeightPx + 2 * borderPx);
ctx.drawImage(image, offsetPx - i * widthPx, paddingPx, newWidthPx, newHeightPx);
}))
}
} else {
let count = Math.ceil((newHeightPx + 2 * paddingPx) / widthPx);
console.log(newHeightPx, widthPx);
let offsetPx = (count * widthPx - newHeightPx) / 2;
for (let i = 0; i < count; i++) {
panes.push(drawImage(function(ctx) {
let rotation = - Math.PI / 2;
ctx.rotate(rotation);
ctx.translate(-heightPx, 0);
ctx.fillStyle = border;
ctx.fillRect(paddingPx - borderPx, offsetPx - i * widthPx - borderPx, newWidthPx + 2 * borderPx, newHeightPx + 2 * borderPx);
ctx.drawImage(image, paddingPx, offsetPx - i * widthPx, newWidthPx, newHeightPx);
}))
}
}
return panes;
}