Jumprit's Knowledge

Jumprit's knowledge and references to share.

Batch Resize in Terminal (Linux) —

Use Imagemagick to resize images in terminal (using mogrify command).

To make life easier, just copy this script and run from your images directory.

#!/bin/bash

function resize {

	mogrify -quality 75 -resize 960 ${1}
	h=$(identify -format %h ${1})
	if [ $h -gt 640 ]; then
		cut=$((($h-640)/2))
		mogrify -quality 100 -shave 0x$cut ${1}
	fi
}

for i in `ls -1 *.JPG *.jpg`; do
	resize ${i}
done

Run it inside a folder with jpg files and it will resize all the files
(it will overwrite the originals).
 
Play with the sizes to fit your needs (max width is 960 and max height is 640).
And you can also adjust quality.
😎

Categorised as: Linux



Leave a Reply