www.voj-tech.net


vt-resize-pictures

Synopsis

vt-resize-pictures is a really simple ImageMagick wrapper written in Bash aimed at batch image resizing. Currently it uses hardcoded parameters and users are encouraged to adjust the script to meet their needs.

Code Example

#!/bin/bash

echo 'Original:'
ls -l *.JPG

vt-resize-pictures.sh
echo

echo 'Resized:'
ls -l resized_pictures/*

# Example output:
# 
# Original:
# -rw-rw-r--. 1 voj-tech voj-tech 4388271 Apr 20  2016 P1050809.JPG
# -rw-rw-r--. 1 voj-tech voj-tech 4531403 Apr 20  2016 P1050810.JPG
# 
# Resized:
# -rw-rw-r--. 1 voj-tech voj-tech 728966 Aug 11 01:25 resized_pictures/P1050809.JPG
# -rw-rw-r--. 1 voj-tech voj-tech 746587 Aug 11 01:25 resized_pictures/P1050810.JPG

Motivation

vt-resize-pictures was originally a script for my personal use but it might come in handy as a template to others as well.

Installation

Prerequisites

It is required that your environment features reasonably new versions of:

  • ImageMagick
  • the find and xargs command line utilities
  • the GNU core utilities
  • Bash

It should be noted that the script has been tested using ImageMagick 6.9.3.0, findutils 4.6.0 (provides the find and xargs utilities), coreutils 8.25 and Bash 4.3.43 on Fedora 25.

Installation Steps

No actual installation is needed. To start using the script follow these steps:

  1. Download a ZIP file with the required version of the script from this page. Most likely you want the latest version.

  2. Unpack the downloaded file and add the execute mode bit to the vt-resize-pictures.sh script file mode bits.

    unzip vt-resize-pictures-0.8.1.zip && chmod +x vt-resize-pictures-0.8.1/vt-resize-pictures.sh
    
  3. Optionally copy the script to a directory which is in your PATH environment variable for convenience. This might be the ~/bin directory for example.

    cp vt-resize-pictures-0.8.1/vt-resize-pictures.sh ~/bin
    

Reference

Usage

./vt-resize-pictures.sh [DIRECTORY]

Resize JPEG images in DIRECTORY (the current directory by default).

Description

The script resizes all the images identified as files with the .jpg filename extension found directly in the specified directory and places the output images to an output directory. The output directory has the name resized_pictures and is created in the directory with the input images. The output images have the same file names as their input counterparts.

The actual operation of resizing the images is done using ImageMagick with a set of hardcoded parameters. The images are resized proportionally and the output images have the width of 1280 pixels, the compression level (quality) of 98 and the sampling factor of 4:2:2.

Exit Status

Typically the vt-resize-pictures.sh script exits with the status of the last command which is to remove a temporary file used internally by the script. This is 0 if it succeeds, otherwise it is a value greater than 0. However the script exits with status:

  • 1 if the output directory cannot be created
  • 2 if no JPEG images are found

Bugs

Suggestions and bug reports are more than welcome at voj-tech@voj-tech.net.