I had taken several screenshots and wanted to align them. They are hard to compare when they don’t match up:
I wrote this quick & dirty program to do that.
For each image:
- Load the image
- Copy it to a <canvas>
- Read the pixels out of the canvas
- Calculate the “center of mass” for all the black pixels
- Also find the minimal rectangle for cropping black pixels, relative to the center of mass
Then for a set of images:
- Calculate the center of mass and dimensions for all of the images
- Calculate the maximal minimal rectangle, relative to the center of mass
- Output crop rectangles relative to the top left
Here is the output, as graphicsmagick commands:
And here’s how it looks — much better!