Skip to content

Instantly share code, notes, and snippets.

@lucas-pelton
Created November 20, 2021 15:12
Show Gist options
  • Save lucas-pelton/f168893f59f09009413c444f7da28677 to your computer and use it in GitHub Desktop.
Save lucas-pelton/f168893f59f09009413c444f7da28677 to your computer and use it in GitHub Desktop.
Size all selected images to similar visual gravity
/*********
*
* resize logos in custom galleries.
*
*/
window.addEventListener("load", function() {
var images = document.querySelectorAll(".custom-gallery img");
var adjustImageWidth = function (image) {
var widthBase = 250;
var scaleFactor = 0.525;
var imageRatio = image.naturalWidth / image.naturalHeight;
image.width = Math.pow(imageRatio, scaleFactor) * widthBase;
}
images.forEach(adjustImageWidth);
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment