Ruby command line (CLI) utility to resize static images for website embedding

Overview

This is a utility program to resize images suitable for web thumbnails and responsive images.

It scans for image files, resizes them, and puts them in a resize/NNN folder where NNN is the image width.

This works amazingly well with my Hedge Court plugin to Jekyll allowing convenient placement of responsive images in static webpages. It is in use on every page of this site.

The program is efficient and can even run on Raspberry Pi 2 models.

Highly flexible command line interface (CLI):

  • Optionally recurse into subdirectories
  • Optionally clobber existing target image files
  • Allows skipping of files specified in .ruby-run-resize-ignore
  • Allows override of the default image file extensions
  • Allows override of the default output dimensions
  • Allows override of the default output folder format

GitHub

Source code is available in the Ruby Run Resize GitHub repository.

Example usage

This is the output of the actual live shell session used to create the thumbnail in the upper right of this page.

sasiela@moroes:/var/jekyll/hc/cards/portfolio/ruby-run-resize $ ls
index.md  r3-screenshot.png
sasiela@moroes:/var/jekyll/hc/cards/portfolio/ruby-run-resize $ ~/ruby-run-resize/ruby-run-resize.rb .
ignore file [.ruby-run-resize-ignore] does not exist or not readable, skipping.
resized [r3-screenshot.png] to width [400], saved to [resized/400/r3-screenshot.png]
resized [r3-screenshot.png] to width [800], saved to [resized/800/r3-screenshot.png]

Processing Summary:
        Scan Count:   1 (total images on site)
        Source Count: 1 (total that needed conversion)
        Target Count: 2 (total output images)
sasiela@moroes:/var/jekyll/hc/cards/portfolio/ruby-run-resize $ ls
index.md  r3-screenshot.png  resized
sasiela@moroes:/var/jekyll/hc/cards/portfolio/ruby-run-resize $ ls resized/
400  800
sasiela@moroes:/var/jekyll/hc/cards/portfolio/ruby-run-resize $ ls resized/400
r3-screenshot.png
sasiela@moroes:/var/jekyll/hc/cards/portfolio/ruby-run-resize $

Output of –help

usage: ruby-run-resize [options] PATH [PATH...]
    -c, --clobber      delete existing output files
    -s, --shallow      do not recurse into directories
    -y, --quality      image quality for output files (1-100), default 95
    -d, --dimensions   comma-delimted list of pixel widths
    -r, --resize-dir   subfolder in which to store resized images, default 'resized'
    -i, --ignore-file  file containing names of images to ignore, default '.ruby-run-resize-ignore'
    -e, --extensions   comma-delmited list of image extensions, including the dot
    -q, --quiet        suppress output (quiet mode)
    -v, --verbose      enable verbose mode
    -h, --help         display help message
    --version          print the version