OsGate.org Logo

Previous Previous | Next Next

Resize images - resize images jpg jpeg png script bash

Script and coding Script and coding

Date 24.03.2013

Visits 1670



This is a bash script used to resize images.

You can use it if you have for example, very big images that you need to upload to a very slow FTP server :D

------- BEGIN BASH SCRIPT -------

#!/bin/bash


mkdir resized

for i in `ls $1 | grep -i jpg`
do
        echo $i
        convert -resize 35% $i resized/$i
done

------- END BASH SCRIPT -------

  • First of all, it creates a directory called "resized" where to store the resized images
  • It takes as argument ($1) the path where the images are located
  • It uses the convert command of ImageMagick to resize the images
  • 35% is the ratio used to resize the height and the width of images. The new width and height will be: old_width*0.35 and old_height*0.35 (example: 3648x2736 => *0.35 => 1277x958) .