This project is not covered by Drupal’s security advisory policy.

Client-Side Media prepares images in the editor's browser before they are uploaded. It scales them down to a maximum size, converts iPhone HEIC photos to JPEG, WebP or AVIF where the browser can decode them, turns sideways photos upright, and removes GPS coordinates and other camera data. When the browser cannot do the work, the server removes the same metadata from JPEG, PNG and WebP files and, within a memory budget, turns and resizes them too. HEIC has no server fallback.

Status: Stable, for production use. 1.0.0 is the first release. Please report anything that does not behave as described in the issue queue.

Why

Editors upload 12-megapixel phone photos straight from their camera roll. The files are large, some hosts run out of memory resizing them, image fields refuse HEIC, Drupal's image toolkit ignores the EXIF orientation tag so derivatives come out sideways, and the GPS position of where each photo was taken ends up in public files. This module does that work on the editor's computer, using only the browser's own APIs: there is no library to download, no WebAssembly and no cross-origin isolation header to set.

Features

In the browser, before upload

  • Scales images down to a maximum width and height (2560 × 2560 pixels by default). It never goes below the field's minimum resolution, and a smaller maximum set on the field wins.
  • Converts HEIC and HEIF photos to JPEG, WebP or AVIF where the browser can decode them: Safari with its own decoder, and Chrome or Edge over HTTPS where the operating system provides an HEVC decoder. Writes WebP through the canvas, and AVIF through WebCodecs' AV1 encoder in a container the module writes itself, since no browser's canvas can write AVIF.
  • Turns sideways photos upright by applying the EXIF orientation to the pixels, so image style derivatives come out the right way up.
  • Removes GPS, EXIF, XMP, IPTC, comments, embedded thumbnails and extra images such as depth and gain maps. When nothing else needs changing, the metadata is taken out of the file's structure and the compressed picture is copied byte for byte, so there is no loss of quality.
  • Re-encodes only when there is a reason: resizing, turning a photo upright, or a format change. A transparent image that would be re-encoded to a format without transparency (JPEG, or AVIF, which the module writes without an alpha channel) is saved instead in a format with transparency that the field accepts and the browser can write: WebP when AVIF was chosen, otherwise the source's own format, then WebP, then PNG. It is drawn over white, never black, only when no such format can be used. The server never changes a format, so it never flattens one. Animated GIF, PNG and WebP files are never decoded, so they keep every frame.
  • Processes one file at a time, with a two-minute limit per file: a step that stalls uploads the original instead and never leaves the field busy.
  • Says what it is doing through Drupal's live region ("Preparing photo.heic…"), leaves a one-line summary per file such as "converted from HEIC to JPEG, resized from 4032 × 3024 to 2560 × 1920 pixels, location data removed (2.9 MB, now 612 KB)", shows errors in a role="alert" region, and stops the form being submitted while images are still being prepared.

Where it works

  • Core's file and image widgets and contributed widgets built on core's managed_file element, Media Library's upload form, and images dropped or pasted into CKEditor 5.
  • Each browser capability is checked when the page runs, not guessed from the browser's name. Resizing, rotation and metadata removal work in current browsers. WebP output needs a browser that can write it (Safari writes JPEG instead). AVIF output needs HTTPS and a WebCodecs AV1 encoder, as in desktop Chrome and Edge; a browser without one writes WebP, or JPEG where it cannot write WebP either, as in Safari.
  • HEIC is converted by Safari's own decoder, over plain HTTP too, and by Chrome and Edge over HTTPS where the operating system provides an HEVC decoder: macOS, and Windows with Microsoft's HEVC Video Extensions. Neither was verified for this release. Other browsers, such as Firefox and Chrome on Linux, refuse a HEIC photo with a message that says what to do instead, such as uploading a JPEG. A file field that accepts HEIC gets the photo unconverted.
  • The scripts load only on pages with a processed upload field or a CKEditor 5 editor: 42 KB gzipped for an upload field.

On the server

  • A server-side check, the ClientSideMediaGuard upload validator, runs on every upload to a processed field. A file the browser already prepared leaves it nothing to do. It does the work for browsers without support, browsers with scripts turned off, and scripts or decoupled front ends sending files through JSON:API, REST or CKEditor 5's upload route. Those three routes are covered through a decorator on core's file.validator service, because core's upload controllers offer no hook to add a validator.
  • It removes metadata from JPEG, PNG and WebP by walking the file's structure, without decoding the picture. The browser and the server produce byte-identical results, which the tests check.
  • It turns images upright and resizes them only within a memory budget: 40 megapixels by default, and never more than what is left of PHP's memory_limit. A larger image is stored at its size with its orientation tag, and the editor is told.
  • Damaged files are handled, not skipped: a file cut short after its header is cleaned up to the damage; one whose header cannot be walked is re-encoded; one that can be neither is stored as uploaded, with a warning to the editor, a log entry and a count on the status report.
  • There is no server fallback for HEIC: PHP's GD cannot read it, so an image field cannot store a HEIC photo that the browser did not convert.

Settings and tools

  • Site defaults on one settings page, which also shows what the browser you are using can do and lists every file and image field with what happens to its uploads.
  • A Client-side image processing section on every image and file field's settings form: use the site default, use settings for this field, or never process uploads to this field. Only formats the field accepts are written; choosing one it does not accept is refused with the extension to add.
  • Drush: client-side-media:fields (csm-fields) lists every file and image field and what happens to its uploads. client-side-media:audit (csm-audit) counts stored JPEG, PNG and WebP files that still carry metadata. With --strip it shows what it would clean; --strip --no-dry-run cleans them after a confirmation, follows each field's settings unless told otherwise, copies the originals to a backup directory (by default private://client_side_media/backups/<date>) with a manifest, and flushes their image style derivatives. --location-only removes only the coordinates and keeps creator and rights data.
  • For developers: hook_client_side_media_settings_alter(), a client-side-media:processed event in the browser, and ManagedFileIntegration::apply() for your own upload elements. The README documents each.

Requirements

  • Drupal 11.3 or later, or Drupal 12.
  • PHP 8.3 or later, with GD (core's default image toolkit). ImageMagick is not needed.
  • Core's File and Image modules. Media Library, CKEditor 5, JSON:API, REST, Field UI and Help are each used when installed and never required. Drush is optional, for the two commands.
  • HTTPS for AVIF output, and for HEIC conversion in browsers other than Safari: both use WebCodecs, which browsers offer only on secure origins. Safari reads HEIC with its own decoder over plain HTTP too, and resizing, rotation and metadata removal work over HTTP everywhere.
  • No database tables of its own: the module stores its configuration and one State entry, the count of uploads stored with metadata that could not be removed, which the status report shows.
  • Tested on MariaDB and SQLite.

Installation

Install with Composer, then enable the module:

composer require drupal/client_side_media
drush en client_side_media

Uploads to every image field are processed with the defaults from then on: at most 2560 × 2560 pixels, the original format kept, quality 82, metadata removed, and HEIC converted to JPEG where the browser can decode it. Images uploaded through CKEditor 5 get the same defaults, within the editor's own maximum dimensions. File fields are left alone until you set one up. To opt image fields in one by one instead, turn off Process uploads to image fields on the settings page; Process images uploaded through CKEditor 5 is a separate switch.

Configuration and permissions

Site defaults are at Administration » Configuration » Media » Client-Side Media (/admin/config/media/client-side-media). Each field's own settings are in the Client-side image processing section of its settings form, and are edited by whoever may edit that field through Field UI.

  • Administer Client-Side Media (not restricted): change the site-wide defaults on the settings page: whether image fields and CKEditor 5 uploads are processed, the maximum size, output format and quality, metadata removal, HEIC conversion, and the largest image the server will turn or resize.

What the server still does

For JPEG, PNG and WebP, the browser's work is an optimization, not something the site relies on. Every check core makes on an upload still runs on the processed file; on the server, this module never relaxes a check and never refuses a file itself. For uploads to processed fields, Media Library, CKEditor 5 and the JSON:API and REST upload routes, the server repeats the metadata removal for JPEG, PNG and WebP, and the size limit within its memory budget, whoever sent the file. HEIC is the exception: only the browser can convert it. The processed image is what is stored; the original is not kept. Set a field to Never process uploads to this field where originals matter.

Known limitations

  • No server fallback for HEIC. A HEIC photo is converted only by a browser that can decode it: Safari, or Chrome or Edge over HTTPS with the operating system's HEVC decoder. Any other browser refuses it with a message, and a file field that accepts HEIC stores it unconverted.
  • HEIC conversion was not verified for this release in Safari, or in Chrome or Edge with an HEVC decoder, and AVIF output was not verified in Firefox. The browsers tested have no HEVC decoder, so the tests cover reading the HEIF container and the refusal, not a real decode.
  • The server removes metadata from JPEG, PNG and WebP only. A HEIC stored on a file field that accepts it, an AVIF sent through an API, or a GIF keeps its metadata on the server path. In the browser, HEIC is converted and AVIF re-encoded, which removes it.
  • Processing runs on the page's main thread, one file at a time: about 0.2 to 0.5 seconds for a 12-megapixel photo on an Apple silicon Mac, measured on a busy machine, and longer on slow phones.
  • When metadata is kept, it survives only a JPEG to JPEG resize. A format change loses date taken and copyright, and the field setting says so.
  • Wide-gamut photos are converted to sRGB when the browser re-encodes them. On the server, an RGB color profile is carried across a turn or resize, but a CMYK or gray JPEG loses its profile, and with ImageMagick mirrored orientations are kept as a tag.
  • The browser's canvas encoders compress less well than the tuned encoders WordPress bundles, at the same quality setting.
  • Contributed widgets built on managed_file are covered by design, not by tests, and the Gin admin theme has not been tested.
  • --location-only removes structured location data: location properties under any name, and values that are exactly one coordinate in a documented list of notations. Coordinates written into a caption stay. A full --strip is the guarantee.

Similar projects

Checked on drupal.org in November 2026.

  • WordPress 7.1 processes images in the browser with a WebAssembly build of libvips in a Web Worker, so the editor stays responsive and its encoders compress better. It runs only in recent Chromium-based browsers, behind a cross-origin isolation header WordPress sends, and bundles LGPL-3.0 libraries that are not on drupal.org's list of third-party code a project may include. This module runs its resizing and cleaning in every current browser, with only the browser's own APIs. Unlike WordPress, it does not keep the original HEIC beside the converted image.
  • DropzoneJS is a drag-and-drop upload widget. Its Entity Browser widget can resize images in the browser. Measured in November 2026 with the Dropzone library it loads, that resize kept the GPS data and the EXIF thumbnail, left HEIC files unchanged and kept the input's format, and a resized sideways photo still came out sideways in Drupal's image style derivatives. Choose it for its upload experience; this module works with core's own widgets and Media Library.
  • IMCE is a file browser for editors. It resizes uploads on the server through core's validator, has no HEIC support and does no processing in the browser. Choose it to browse and manage files; it solves a different problem.
  • EXIF Orientation turns uploaded images upright on the server from their orientation tag. Choose it if orientation is all you need. This module also does it in the browser, and on the server only within a memory budget.
  • Cloudinary's Upload Widget scales images down in the browser before uploading them to Cloudinary's own servers, a hosted service with free and paid plans. Choose it if your media already lives at Cloudinary. This module keeps files on your own site.

Support and maintenance

Report bugs and ask for features in the issue queue. Each release has notes describing what changed.

This project is not covered by Drupal's security advisory policy. Until it is, security issues are handled in the public issue queue and fixed in ordinary releases.

Maintainer

Created and maintained by deadnorth (Dead North).

Project information

Releases