Converting images on mass.

This only works if you have access to a linux box or have the convert program installed on your computer.

I had 20 images of size 350×350, I needed to resize them, and grab the middle portion of each image. I could use gimp and spend an hour of mind numbing boredom to do this or I could write a little script to do it.Here is the script. (Remember this is for Linux not windows)

for i in `ls *.png`; do echo $i; convert -size 98×98 $i -resize 98×98 -crop 74×74+12+12 +repage +profile ‘*’ small/$i ; done

This script:

  1. lists all the png files in the current directory
  2. it first resize all the pictures to 98px by 98px
  3. it then crops these 74px by 74px, cutting out the middle 74×74 (74+24=98)
  4. it repages the canvas so the 74×74 starts at1:1, not 12:12
  5. it cleans out all profile information
  6. and put the file in a sub directory of small, current to where you are.

Just had a situation to day, [Nov 9th 2012], where I needed flags for all countries of the world. From here,, I found just what I wanted, except they where 256×256, a bit to big for today’s project. So to over come this quickly, I did not what to go though 230 odd files and resize them down to 64×64, I used this script.

  1. First changed dir to the flags dir.
  2. Made a new dir called sm64
  3. Ran this script
  4. for i in `ls *.png`; do echo $i; convert -size 64×64 $i -resize 64×64 +repage +profile ‘*’ sm64/$i ; done

About howlmc

50 something geek, who has owned way too many computers.
This entry was posted in Geek Out, Software, Websites. Bookmark the permalink.