I have several image files in a directory. These images are similar size and have same background color.
How can I make all images same size by adding background like this attached image?
This should work with all the image types that ImageMagick can handle without having to specify
This will move the original images into a dated directory in case the results are not desirable. Also, this will fail if, for whatever reason, the image files have newlines in their names.
This script could do with some more error messages to give a helpful indication if anything went wrong. But for now if there is any error moving the images (everything between the
As long as you select a target size that is larger than your largest image, you should be fine with the following:
The command above will change the original file, you might want to backup before running it. It uses
To make sure you don't loose any image data, ensure that the size you use is larger or as large as the largest image you have. To get that quickly, try:
That should print the sizes of all images sorted and you can easily find the largest.
To appease goldilocks (:P), you can automate the whole process:
I took the opportunity to improve my bash skills and came up with this:
This should do the trick: it first loops over all files (change according to your needs) to find the largest width and height and then loops again to add the required borders (change the