This module uses the compressor.js library to enforce image size limits directly in the user's browser. This is particularly helpful for websites hosted on servers that cannot handle large image files or fail to resize them automatically.
Image Compressor resizes images in the browser before they are uploaded, so the server receives a file that already fits the field's maximum dimensions. It uses the Compressor.js library.
It is meant for hosts where server-side resizing is unreliable. On some platforms, large originals exceed memory or upload limits, or GD or ImageMagick fails to scale them, often without an error. Resizing on the client avoids those failures and reduces upload time and bandwidth.
How it works
- The module watches image field widgets that have a Maximum image dimensions setting.
- When a user chooses a file, the browser scales it down to fit within that width and height, keeping the aspect ratio, and re-encodes it at Compressor.js's default quality (0.8).
- The resized file then replaces the original in the file input, and Drupal's normal AJAX upload runs. Server-side validation still applies.
- Images already within the limits are left alone. If re-encoding would produce a larger file, the original is kept.
- Multiple-file uploads are supported. All files are processed before the upload starts.
Requirements
- Drupal 11.2 or later, or Drupal 12.
- Core Image module.
- Compressor.js is bundled with the module. No separate library download is needed.
Installation and use
- Install the module as usual:
composer require drupal/image_compressor, thendrush en image_compressor. - On each image field that should be resized, set Maximum image dimensions in the field settings, for example
2400 × 2400. - No other configuration is needed. Widgets without a maximum are not affected.
How this module is built
Changes to this module since 2026 were drafted with an AI coding assistant (Claude Code). The maintainers review, test and take responsibility for every change, and the tests and code checks run on drupal.org's CI. Contributions follow Drupal's policy on the use of AI when contributing.
Supporting this module
Developed and maintained by Tyler Brown Cifu Shuster of FivePaths, LLC. Development sponsored by FivePaths.
Ask your assistant about Image Compressor
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
- image Drupal core
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.