Image shrink bash script

Today I just want to upload a little bash script I often use for shrinking my pictures to reduce their size. This is useful for sending by mail or uploading to facebook.

GUIs are very cumbersome if you want to convert a lot of files, but ImageMagick is a great commandline tool for processing pictures. ImageMagick can do a lot, but here I only use the ‘resize’ function of ImageMagick’s ‘convert’ tool.

How to use? Just enter your folder with jpg images and call ‘/path/to/makesmall.sh’. You can also put it into /usr/local/bin to avoid entering the full path.

You can download it from Pastebin or just copy/paste it from here. This link will stay valid for one year.

This post is not for Linux Gurus, but maybe it’s useful for some newbies 😉

 1 #!/bin/bash
 2 # Description: Little script to shrink all images in the current folder.
 3 #  That’s convenient if you want to send them by mail or want to upload it to facebook.
 4 # Author: Gerhard Gappmeier
 5 # License: GPL – GNU General Public License
 6
 7 if [ -e small ]; then
 8   echo "folder ‘small’ exists"
 9 else
10   echo "creating folder ‘small’"
11   mkdir small
12 fi
13
14 for file in *.{jpg,JPG}; do
15   if [ -e "$file" ]; then
16     if [ -e "small/$file" ]; then
17       echo "Skipping ‘$file‘, because ‘small/$file‘ already exists."
18     else
19       echo "Converting ‘$file‘…"
20       convert -resize 1024 "$file" "small/$file"
21     fi
22   fi
23 done
Advertisements

0 Responses to “Image shrink bash script”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: