ShortPixel Command Line Tool

ShortPixel Command Line Tool can optimize image folders from the command line, so it can be configured as a Cron (or other task scheduler) job. You need to have PHP installed in order for it to run.

Installation

Download the latest stable release: ShortPixel PHP SDK v. 0.9.3 and unpack it. You should find a shortpixel-php-master subfolder that was extracted from the archive. Inside shortpixel-php-master/lib you find cmdShortpixelOptimize.php which is the main script of the ShortPixel Command Line Tool.

Optimizing folders

Manually: Run the following commands, while in the site's root folder:


 cd shortpixel-php-master/lib

 php cmdShortpixelOptimize.php --apiKey=<<YOUR_API_KEY>> --folder=<<FOLDER_PATH>> 

The Command Line Tool accepts the following parameters:

Parameter Meaning
apiKey Required. Your API Key. If you don't have one yet, you can request one for free in our Sign-up page.
folder Required. The path of the folder, either full or relative to the current folder. You need to have write rights to all files and subfolders in it.
webPath WORK IN PROGRESS Optional. Map the folder to a web URL and have the ShortPixel servers download the images instead of posting them (less heavy on memory for large files).
Specify as --webPath=http://yoursites.address/img/folder/
backupBase Optional. Backup base path. The folder to be optimized will be first copied there, only if it's not found there already.
Specify as --backupBase=<<BACKUPS_FOLDER_PATH>>
speed Optional. Set between 1 and 10 - default is 10 but if you have large images it will eat up a lot of memory when creating the post messages so sometimes you might need to lower it. Not needed when using the webPath mapping.
Specify as --speed=X
verbose Optional. Display info about the files optimized. Specify as --verbose
clearLock Optional. Clear a lock that's already placed on the folder. BE SURE you know what you're doing, files might get corrupted if the previous script is still running. The locks expire in 6 minutes. Specify as --clearLock

Cron job: add the same command to your scheduler, optionally appending  2>&1 1>/your/log/file. The ShortPixel Command Line Tool has a locking mechanism in place, so if another instance is already running on the same folder, it exits.