Skip to content

Instantly share code, notes, and snippets.

@lucymtc
Created April 11, 2017 21:53
Show Gist options
  • Select an option

  • Save lucymtc/4d04b2507c6614f79b8c1c82057c0b8c to your computer and use it in GitHub Desktop.

Select an option

Save lucymtc/4d04b2507c6614f79b8c1c82057c0b8c to your computer and use it in GitHub Desktop.
Get resized width and height of an image maintaining its aspect ratio
var originalWidth = 2205;
var originalHeight = 3500;
var maxSize = 160;
/** Thumbnails max width and height. */
var ratio = Math.min( maxSize / originalWidth, maxSize / originalHeight );
var thumbWidth = originalWidth * ratio;
var thumbHeight = originalHeight * ratio;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment