Skip to content

Instantly share code, notes, and snippets.

// Choose the area constraint.
// Here the image can't occupy more than 20% of its container.
const maxArea = container.width * container.height * 0.2;
// Choose the height and width constraints.
// In this case the container minus 20px on each side for padding.
const maxWidth = container.width - 20 * 2;
const maxHeight = container.height - 20 * 2;
// Get the native aspect ratio of the image.