Installation¶
The module needs the Compressor.js library in the libraries directory, at libraries/compressorjs/dist/compressor.min.js in the web root. It is not included with the module.
With Composer¶
On a drupal/recommended-project site, run these from the project root. The first four commands let Composer install npm packages from Asset Packagist into web/libraries. Skip them if the site already does that.
composer config repositories.asset-packagist composer https://asset-packagist.org
composer config --json extra.installer-types '["npm-asset"]'
composer config --json 'extra.installer-paths.web/libraries/{$name}' '["type:drupal-library", "type:npm-asset"]'
composer config allow-plugins.oomphinc/composer-installers-extender true
composer require oomphinc/composer-installers-extender npm-asset/compressorjs drupal/image_compressor
drush en image_compressor
Or enable Image Compressor at Extend (/admin/modules) instead of with Drush. The module depends on the core Image module, which Drupal enables with it if needed.
Without Composer¶
- Download Compressor.js 1.3 or later from npm or GitHub.
- Copy its
dist/compressor.min.jstolibraries/compressorjs/dist/compressor.min.jsin the web root. Asites/default/librariesor install profilelibrariesdirectory also works. - Install the module as usual and enable it.
- Rebuild caches if the library was added after the module was enabled.
Checking the installation¶
Reports » Status report (/admin/reports/status) shows Image Compressor: Compressor.js with the path it was found at. Until it is found, the entry is an error, and image fields upload the original file as if the module were not installed.
Upgrading from a version with the bundled library¶
Earlier 1.0.x-dev snapshots included Compressor.js in js/vendor/. Install the library as above before or right after updating, then rebuild caches.
Requirements¶
| Requirement | Version |
|---|---|
| Drupal core | 11.2 or later, or 12 |
| Core modules | Image (and File, which Image requires) |
| Library | Compressor.js 1.3 or later, tested with 1.3.0 and 1.4.0 |
| Browser | Any browser that supports DataTransfer and canvas, which includes all current desktop and mobile browsers |
Uninstalling¶
The module stores no configuration, state or data. Uninstall it at Extend » Uninstall or with drush pmu image_compressor. Image fields then go back to uploading the original file and resizing it on the server.