This is a simple one.

Screen Shot Previews

I want to convert every *.png in a folder to a new image with a width of 480px and with the infix .sm added to the filename.

for i in $(ls *.png | grep -v "sm.png"); do convert -resize 480 $i $(basename $i png)sm.png; done

The ls *.png part finds all *.png images in the current diretory. The grep -v "sm.png" part avoids the script from creating small images from small images. The convert -resize 480 $i $(basename $i png)sm.png; part converts the image to a new image with a width of 480 and ads the .sm infix. The for i in $(...); do; done repeats this step for every image.

Article Preview images

To create the tiny square preview images for posts, I convert any *.png file found in the source directory to be a centered, square preview of this image with the size 256x256.

for i in $(ls *.png | grep -v "pv.png"); do convert $i -thumbnail 256x256^ -gravity center -extent 256x256 $(basename $i png)pv.png; done

The ls *.png part finds all *.png images in the current diretory. The grep -v "pv.png" part avoids the duplication, as described above. The convert $i -thumbnail 256x256^ -gravity center -extent 256x256 is the magic required to create the preivew. The for i in $(...); do; done repeats this step for every image.