Image resizing tool for Ubuntu

i have around 500 images and i need to resize each into 6 different sizes. Can any there scripts or software. moreover my platform is ubuntu .


Solution 1:

Please try to use ImageMagick. First, install it:

$ sudo apt-get install imagemagick

Then you can make a little bash script to convert them to your 6 sizes:

#!/bin/bash

# List all the formats you wish to have
SIZES="640x480 800x600 1024x768"

# pass directory as first argument to the script
# Use '.' (current directory) if no argument was passed
DIR=${1:-.}

find $DIR -type f | while read file; do
   for size in $SIZES; do
      # Resize and rename DSC01258.JPG into DSC01258_640x480.JPG, etc.
      # Remove the ! after $size if you do not wish to force the format
      convert -resize "${size}!" "$file" "${file%.*}_${size}.${file##*.}"
   done
done

Save the script as, e.g. convert.sh, and run:

chmod +x convert.sh
./convert.sh /path/to/directory # path is optional, it takes '.' as default

Edit: I edited the script to make sure to not override files when resizing, but rename them to e.g. DSC01258_640x480.JPG, and use convert instead of mogrify since the files are actually renamed. I also sanitized the variables a bit, doesn't hurt.

I tested the script with png files and it worked fine. It should work for all kinds of image formats supported by ImageMagick:

$ file wave_bible_bot/*
  wave_bible_bot/wave_bible_bot1.png: PNG image, 516 x 308, 8-bit/color RGB, non-interlaced
  wave_bible_bot/wave_bible_bot2.png: PNG image, 515 x 428, 8-bit/color RGB, non-interlaced
  wave_bible_bot/wave_bible_bot3.png: PNG image, 565 x 384, 8-bit/color RGB, non-interlaced

$ ./resize.sh wave_bible_bot/

$ file wave_bible_bot/*
  wave_bible_bot/wave_bible_bot1_1024x768.png: PNG image, 1024 x 768, 8-bit/color RGB, non-interlaced
  wave_bible_bot/wave_bible_bot1_640x480.png:  PNG image, 640 x 480, 8-bit/color RGB, non-interlaced
  wave_bible_bot/wave_bible_bot1_800x600.png:  PNG image, 800 x 600, 8-bit/color RGB, non-interlaced
  wave_bible_bot/wave_bible_bot1.png:          PNG image, 516 x 308, 8-bit/color RGB, non-interlaced
  wave_bible_bot/wave_bible_bot2_1024x768.png: PNG image, 1024 x 768, 8-bit/color RGB, non-interlaced
  wave_bible_bot/wave_bible_bot2_640x480.png:  PNG image, 640 x 480, 8-bit/color RGB, non-interlaced
  wave_bible_bot/wave_bible_bot2_800x600.png:  PNG image, 800 x 600, 8-bit/color RGB, non-interlaced
  wave_bible_bot/wave_bible_bot2.png:          PNG image, 515 x 428, 8-bit/color RGB, non-interlaced
  wave_bible_bot/wave_bible_bot3_1024x768.png: PNG image, 1024 x 768, 8-bit/color RGB, non-interlaced
  wave_bible_bot/wave_bible_bot3_640x480.png:  PNG image, 640 x 480, 8-bit/color RGB, non-interlaced
  wave_bible_bot/wave_bible_bot3_800x600.png:  PNG image, 800 x 600, 8-bit/color RGB, non-interlaced
  wave_bible_bot/wave_bible_bot3.png:          PNG image, 565 x 384, 8-bit/color RGB, non-interlaced

Solution 2:

If you install ImageMagick as Sathya mentioned, there is a nice GUI frontend to make resizing easier called nautilus-image-converter.

To install it:

sudo apt-get install nautilus-image-converter

Restart nautilus (or log out and back in). It will add "Resize Images" and "Rotate Images" to your context menu as shown here:

alt text

Simply highlight all images you want to resize, right-click, select Resize Images, and you will get this interface:

alt text

Use the "Append" option and add a custom name to your resized images. You may want to append the size such as 1024x768 OR you can make 6 copies of your images in different folders, then use the resize images in place option on the images in each folder to overwrite them with new images that have different dimensions. Resize images in place will always overwrite the selected images, so be careful what you select!

Solution 3:

You can use ImageMagick: First install ImageMagick

sudo apt-get install imagemagick

Next, cd to the location where your images are there:

cd /path/to/where/images/are/stored

Next, create directories according to your Imagesize

mkdir /path/to/where/images/are/stored/size

Copy the images to the directory where you wish to transform

cp /path/to/where/images/are/stored/* /path/to/where/images/are/stored/size

Next, change the directory to the other directory

cp /path/to/where/images/are/stored/size

Then, use a tool called mogrify provided by ImageMagick library to resize

mogrify -resize 640×480! *.jpg

This will resize all to 640*480, ! tells to force aspect ratio.

I don't know Bash scripting, so its not that automated.

Solution 4:

There really should be several references to mogrify tool in the convert's manual. ... I searched for about forty-five minutes but it wasn't until I came across another post that I was able to start looking in the right direction.

For the benefit of others this line did exactly what I needed. It took about fifty 2meg to 3meg JPGs (in the same directory) and dropped them all down to 80 to 120 kb. And of course it left all of their names 'exactly' the same.

mogrify *.jpg -quality 75 -resize "640x480>" *

And, again for the benefit of others:

  • *.jpg ... performs the mogrify command on all JPGs in the directory.

  • -quality 75 ... cuts the jpg quality down to 75% which is plenty for online viewing.

  • -resize "640x480>" ... causes all of the images to be resized to 640x480 (notice the ">" at the end. That makes images smaller but 'not' larger. ... and don't forget the quotes; those are important.

  • * ... and don't forget this at the very end of the command.

Solution 5:

I would recommend phatch. Its GUI is a lot more flexible than what imagemagick and nautilus have to offer and it has a command line interface too, if you need to write a script. You can install it with

sudo apt-get install phatch