Skip to content

Instantly share code, notes, and snippets.

@marlonmarcello
Created June 9, 2017 18:36
Show Gist options
  • Save marlonmarcello/7e24d6d8b15e26604514de25042599a7 to your computer and use it in GitHub Desktop.
Save marlonmarcello/7e24d6d8b15e26604514de25042599a7 to your computer and use it in GitHub Desktop.
Changing a set of values to a different ratio
function changeRatio(originalWidth, originalHeight, newWidth = 750, newHeight = 420, restrain = false) {
let ratio = w / h,
targetRatio = targetW / targetH;
let newW = targetW,
newH = newW / ratio;
if (restrain && newH > targetH) {
newH = targetH;
newW = newH * ratio;
}
return {width: newW, height: newH}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment