Sunday, April 29, 2012

Resizing Images from the Command Line

I love the power of the Linux command line. I am working on resizing images and I was able to resize only the ones I wanted with a few commands. Here is what I came up with:
# Get only the files with a vertical or horizontal resolution of 4320px;
# the output is the file name followed by the resolution:
find . -name "*.JPG" -exec identify -format "%d/%f %wx%h" {} \; | grep 4320 > files.txt

# Get just the file name:
awk -F ' ' '{ print $1 }' < files.txt > files2resize.txt

# Resize the photos:
for i in `cat files2resize.txt`; do 
    mogrify -verbose -resize '2816x2816>' "$i"; 

No comments:

Post a Comment