Skip to content

Instantly share code, notes, and snippets.

@jvcleave
Created December 26, 2018 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvcleave/c44c57a2bd84f14959b071fa5532c1dc to your computer and use it in GitHub Desktop.
Save jvcleave/c44c57a2bd84f14959b071fa5532c1dc to your computer and use it in GitHub Desktop.
aspect ratio
static ofVec2f getFitAspectRatioSize(float maxWidth, float maxHeight, float imgWidth, float imgHeight)
{
ofVec2f result;
float widthRatio = maxWidth / imgWidth;
float heightRatio = maxHeight / imgHeight;
float bestRatio = min(widthRatio, heightRatio);
result.x = imgWidth * bestRatio;
result.y = imgHeight * bestRatio;
return result;
}
static ofVec2f getFitAspectRatioSize(ofVec2f windowSize, float imgWidth, float imgHeight)
{
return getFitAspectRatioSize(windowSize.x, windowSize.y, imgWidth, imgHeight);
}
static ofVec2f getFitAspectRatioSize(ofVec2f windowSize, ofImage& image)
{
return getFitAspectRatioSize(windowSize, image.getWidth(), image.getHeight());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment