Skip to content

Instantly share code, notes, and snippets.

@pedrobritto
Created July 16, 2019 19:22
Show Gist options
  • Save pedrobritto/c9f561e5db9db736bb323a6346867113 to your computer and use it in GitHub Desktop.
Save pedrobritto/c9f561e5db9db736bb323a6346867113 to your computer and use it in GitHub Desktop.
class ImageResizer {
constructor(minWidth, minHeight) {
this.minWidth = minWidth;
this.minHeight = minHeight;
this.imageDimension = [1000, 500];
this.imageProportion = this.imageDimension[0] / this.imageDimension[1];
}
resize() {
// Generate image proportion
// If image width is greater than minWidth
// calculate new dimensions based on width
// If image height is smaller than minHeight
// calculate new dimensions based on height
// Return new height
let newDimensions = [];
if (this.imageDimension[0] > this.minWidth) {
newDimensions[0] = this.minWidth;
newDimensions[1] = this.minHeight / this.imageProportion;
}
if (newDimensions[1] < this.minHeight) {
newDimensions[1] = this.minHeight;
newDimensions[0] = this.minWidth / this.imageProportion;
console.log("woops!");
}
return newDimensions;
}
}
const imageResizer = new ImageResizer(500, 500);
console.log(imageResizer);
console.log(imageResizer.resize());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment