We need to have huge amounts of png’s resized to be divisible by 12, each png is variable in size and the image needs to stay 1:1 in the top left.
At the moment were having to manually bring in each file into Photoshop and enlarge the canvas on the x+y to be divisible by 12 and keep the image in the top left corner. With the amount of png’s we need doing now and in future we need an automated process.
2
Answers
Never mind, this is a possible solution for your problem. This script will run in MATLAB or Octave (Octave is an open-source alternative to MATLAB, so you might want to use that.)
Copy the following function into a file and call it
resizeIm.m
. Then start Octave and call this function for every image you have.The function can be called by
I would do this with ImageMagick, which is free and installed on most Linux distros and also available for OSX and Windows from here.
This little
bash
script will resize all the PNG files in the current directory and save them with the original name in the subdirectory calledoutput
. It is pretty easy to read – it basically loops through all the PNG files in the directory. It then uses ImageMagick’s built-in calculator to work out the size of your output file as nearest multiple of 12. Then it loads the image and extends the background using transparent pixels (-background none
) to that size (using-extent
) and leaves the original image in the top-left corner (-gravity NorthWest
).P.S. If installing
ImageMagick
on OSX, please ask for advice before trying.P.P.S. If you have 10,000+ images to resize, and you do it often, and you are on OSX or Linux (probably not Windows), I would recommend
GNU Parallel
. If that is likely, please ask.