/large-images-drush

Provides a few utilities for identifying and compressing large images in a Drupal website using Drush

Primary LanguagePHP

Introduction

This provides two drush commands.

  1. large-images-list will list the largest images (by file size) found in a directory (and its subdirectories by default)
  2. large-images-compress will compress (shrink file size of) images and update the associated record in Drupal's file_managed table
  • Both of these commands require you to specify the directory to search, and the minimum size you'd like to operate on.
  • Both of these commands also allow you to specify a maxdepth.
  • The compression command takes an additional (required) "quality" argument. This can be anything from 1 to 100 (lowest output quality to highest output quality). For general use the recommended value is somewhere around 80 or 90.
  • Run either command with --help to see all options. For example: drush large-images-list --help

Warning

  • Run large-images-list before running large-images-compress
  • Use the --backup option to automatically create originalfile.jpg_lgbak files
  • These commands work fine in the environments where I've used them. This does not mean they'll work perfectly for you! Test before using!
  • I recommend you back up your Drupal database and whatever directory you're operating on before executing large-images-compress
  • large-images-compress is not a "smart" command. It simply overwrites the image with the desired output quality and updates the database. It does not look at the current compression level before attempting to generate the new version, though I may add this functionality to prevent trying to go from a lower quality to a higher one.

Requirements

  • Drupal 7 site
  • drush
  • php with gd library
  • find command
  • du command
  • sort command (some systems may be missing the -h option; you may remove this h option in the code without affecting the functionality)
  • cut command

Installation

  1. Place the large_images.drush.inc file into ~/.drush/
  2. Run drush cc drush
  3. Run drush large-images-list --help to see if it's recognized

Example 1

Example 1

Example 2

Example 2

Example 3