Command-Line Reference

Name

jchoptimize:optimize-images — Optimize images on a schedule, continuing where the last run stopped Joomla Pro

Synopsis

php cli/joomla.php jchoptimize:optimize-images [--mode={ urls | folders }] [--base-url=URL] [--crawl-limit=number] [--folder=folder...] [ --recursive | --no-recursive ] [--time-limit=seconds] [ --notify | --no-notify ] [--notify-email=addresses] [--live-site=URL]

Description

Optimizes images with your image optimization settings, for at most --time-limit seconds, then stops and leaves the rest for the next run. Run it often enough to get through your images, for example every 30 minutes. It needs your Download ID and a plan that includes image optimization.

It works in one of two modes:

--mode=urls (the default)

Crawls your site's pages and optimizes the images found on them, like Optimize By URLs. The crawl starts at --base-url (absolute, or relative to your site, such as /sitemap.html), or else the Base URL setting, or else your home page.

--mode=folders

Optimizes the images in the folders given with --folder, like Optimize By Folders.

The command remembers the job it is working on and continues it while you keep the same mode, folders and starting page; changing any of them starts a new job. Only one run works at a time. Images that are already optimized with the current image settings are skipped while Ignore optimized images is on, so they don't use your image credits again. When your plan's credits run out, the job pauses and continues by itself; see the section called “When Your Plan's Image Credits Run Out”.

The JCH Optimize - Optimize images scheduled task does the same from Joomla's scheduler, with the same choices, and works on the same job. Use the task or this command, not both; see the section called “Optimize Images Automatically”.

Options

--mode

urls or folders. The default is urls.

--base-url

URLs mode: the page the crawl starts from.

--crawl-limit, -l

URLs mode: the maximum number of pages crawled. Overrides the Crawl limit setting.

--folder, -f

Folders mode: a folder inside your site, relative to its root. Repeat it for several folders. The default is /images/.

--recursive, --no-recursive

Folders mode: include or skip subfolders. Overrides the Recurse in subfolders setting.

--time-limit, -t

The most seconds this run spends optimizing. The default is 300.

--notify, --no-notify

Email, or don't, when optimization pauses for your plan's limits or stops because of an error, at most once a day. The default is to email.

--notify-email

Addresses to email, separated by commas. The default is the super users who receive system emails.

Options apply to this run only; nothing is saved. All other image options (WebP, AVIF, responsive images, compression, quality) come from the settings.

Examples

Optimize the images found on your pages, every 30 minutes:

*/30 * * * * /usr/bin/php /path/to/site/cli/joomla.php jchoptimize:optimize-images --live-site=https://www.example.com/ --quiet

Optimize the images in /images/, without its subfolders:

*/30 * * * * /usr/bin/php /path/to/site/cli/joomla.php jchoptimize:optimize-images --mode=folders --folder=/images/ --no-recursive --quiet

Tip

Run the command once by hand before adding it to CRON. It prints what it did and how the job stands, so you can check it reaches your site and optimizes images.