Oct
13
Resizing photos in bulk
I recently had to create a simple batch script to resize a massive number of images quickly. The server on which the job was going to run had 16 CPUs so wanted to ensure that all the processing power will be utilised.
I started off with Python but soon realised that there is a much easier way of doing it. The server had a minimal Linux install but surprisingly ImageMagick was there. A quick look at man pages and I came up with:
find . -name "*.[Jj][Pp][Gg]" -type f -print0 | xargs -0 -P16 -I'{}' convert -verbose -quality 100 -resize 10% {} {}
Some people install GNU Parallel for this, but there’s the -P option in xargs already. The bonus is that find and xargs are core components of virtually every Linux distro out there.