This provides two drush commands.
large-images-list
will list the largest images (by file size) found in a directory (and its subdirectories by default)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
- Run
large-images-list
before runninglarge-images-compress
- Use the
--backup
option to automatically createoriginalfile.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.
- Drupal 7 site
- drush
- php with gd library
find
commanddu
commandsort
command (some systems may be missing the -h option; you may remove thish
option in the code without affecting the functionality)cut
command
- Place the
large_images.drush.inc
file into~/.drush/
- Run
drush cc drush
- Run
drush large-images-list --help
to see if it's recognized