Skip to content

Instantly share code, notes, and snippets.

@mCzolko
Created October 29, 2018 14:44
Show Gist options
  • Save mCzolko/87c429e2068c847f144c1fcb0f9fb352 to your computer and use it in GitHub Desktop.
Save mCzolko/87c429e2068c847f144c1fcb0f9fb352 to your computer and use it in GitHub Desktop.
const CANVAS_WIDTH = 1000;
const CANVAS_HEIGHT = 800;
function resizeImage(imageWidth, imageHeight) {
const ratio = imageWidth / imageHeight;
let width = CANVAS_WIDTH;
let height = width / ratio;
if (height > CANVAS_HEIGHT) {
height = CANVAS_HEIGHT;
width = height * ratio;
}
return {
width,
height,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment