Accurately determining the size of an image file sounds simple but the devil is in the details. This is especially true if there are lots of images, the files are stored in S3 or anywhere else that isn’t your local machine, if you have corrupt images mixed in there or any other complexities that come up in the real world.
Personally, I like to throw together a proof of concept when experimenting with third party modules or other tools I have not used before. I’ve been writing code a long time now and now I don’t believe anything works until I see it in action.
Given my wariness I decided to write some throwaway code around figuring out image dimensions in Typescript. The code I am putting up on github is in no way a comprehensive examination, nor is it good for much of anything aside from serving as a starting point for anyone wanting to test out the ‘image-size’ and ‘jimp’ image modules.
The code is at https://github.com/andyjdavis/image-size-test