Skip to content

Instantly share code, notes, and snippets.

@crrmacarse
Last active January 28, 2020 07:41
Show Gist options
  • Save crrmacarse/15203116c8dd5f128438d296fa4b25b7 to your computer and use it in GitHub Desktop.
Save crrmacarse/15203116c8dd5f128438d296fa4b25b7 to your computer and use it in GitHub Desktop.
Image Crop Helper
export const scaleX = (baseWidth, width) => Math.round(baseWidth / width);
export const scaleY = (baseHeight, width) => Math.round(baseHeight / width);
export const cropXvalue = (x, scaleXvalue) => Math.round(x * scaleXvalue);
export const cropYvalue = (y, scaleYvalue) => Math.round(y * scaleYvalue);
export const cropWidthValue = (width, scaleXValue) => Math.round(width * scaleXValue);
export const cropHeightValue = (height, scaleYValue) => Math.round(height * scaleYValue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment