npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

optically-size-images

v1.0.0

Published

Normalize the size of a group of images, optically, based on their aspect ratios

Readme

optically-size-images

Normalize the size of a set of images, optically, based on their aspect ratios. See it in action on this Codepen.

grid of logos, before and after normalization

What is this?

This is a small script that loops through all the images of a specified container and resizes them to be similarly sized. This is especially handy on logos, but has other applications as well (product images, etc).

Why not scale the images manually?

The absolute best way to insure a set of images always looks sized properly in relation to each other is to manually size them within the same-sized containers. Many times this isn't feasible or a good use of time. This also becomes problematic when there are many images or they need to be added dynamically from a backend (from client).

Why not just use object-fit?

This solution does use object-fit, but there are limitations to the amount of normalization that can happen with object-fit. Even with max-height and other tricks, images with different aspect-ratios will always appear as different visual sizes. object-fit vs script

The solution - Scaling along a curve

The solution for this is to set the scale amount based on where the image's aspect ratio lands on a curve:

Scaling along a curve

So, the wider an image, the less it scales, the closer it gets to square, the more it scales. (For logos taller than 1:1 the script essentially reverses the process back down the curve.)

Usage

  1. Add a container with the class .arScale that holds your images. Each image will also need to have a parent container (ie div or figure)
<div class="arScale">
  <figure><img src="img1.jpg" /></figure>
  <figure><img src="img2.jpg" /></figure>
  <figure><img src="img2.jpg" /></figure>
</div>
  1. Attach or add the javascript file:
<script src="path-to/optically-size-images.js"></script>

You can also add this and the css with npm.

  1. Add required css:
/* modify container to suit your needs */
.arScale {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-gap: 3%;
  column-gap: 6%;
}
/* required */
.arScale > * {
  margin: 0;
  padding: 0;
  border: 0;
  vertical-align: baseline;
  aspect-ratio: 1/1;
  text-align: center;
  display: flex;
  align-items: center;
}
/* required */
.arScale img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.2s ease;
  transform: scale(var(--scaleBy));
}

The script will find the height and with of any image in that container then scale it accordingly.