Repository navigation
Description
I asked Claude to dig into this one, here is what it found:
When a HEIC photo is uploaded and the server lacks support for the format, and client side media processing is enabled, the attachment is converted to a JPEG in the browser and loses all of its EXIF and IPTC metadata. No title or caption is suggested from the photo, and image_meta in the attachment metadata comes back empty, so the camera, credit, copyright and capture timestamp are gone. Uploading the same photo to a server that can decode HEIC keeps all of it.
The cause is the conversion step. HEIC is not in CLIENT_SIDE_SUPPORTED_MIME_TYPES (
gutenberg/packages/upload-media/src/store/constants.ts
Lines 39 to 45 in 75768b4
| export const CLIENT_SIDE_SUPPORTED_MIME_TYPES: readonly string[] = [ | |
| 'image/jpeg', | |
| 'image/png', | |
| 'image/gif', | |
| 'image/webp', | |
| 'image/avif', | |
| ] as const; |
prepareItem() routes it to the canvas fallback: gutenberg/packages/upload-media/src/store/private-actions.ts
Lines 874 to 903 in 75768b4
| } else if ( isImage && isHeic ) { | |
| // HEIC/HEIF: convert to JPEG client-side before upload. | |
| // The server may not support HEIC, so decode it using the | |
| // browser's native HEVC codec (createImageBitmap or VideoDecoder) | |
| // and upload the resulting JPEG. The server then handles it like | |
| // any normal JPEG (threshold scaling, sub-sizes, etc.). | |
| // This matches iOS behavior where HEIC is converted on the fly. | |
| try { | |
| heicJpeg = await canvasConvertToJpeg( | |
| file, | |
| settings.imageQuality ?? DEFAULT_OUTPUT_QUALITY | |
| ); | |
| } catch { | |
| dispatch.cancelItem( | |
| id, | |
| new UploadError( { | |
| code: ErrorCode.HEIC_DECODE_ERROR, | |
| message: getHeicUnsupportedMessage(), | |
| file, | |
| } ) | |
| ); | |
| return; | |
| } | |
| operations.push( | |
| OperationType.Upload, | |
| OperationType.ThumbnailGeneration, | |
| OperationType.Finalize | |
| ); | |
| } else { |
That calls canvasConvertToJpeg(), which draws the decoded bitmap onto a canvas and re-encodes it:
gutenberg/packages/upload-media/src/canvas-utils.ts
Lines 23 to 52 in 75768b4
| export async function canvasConvertToJpeg( | |
| file: File, | |
| quality = 0.82 | |
| ): Promise< File > { | |
| const baseName = getFileBasename( file.name ); | |
| // Strategy 1: createImageBitmap + OffscreenCanvas. | |
| try { | |
| const bitmap = await createImageBitmap( file ); | |
| try { | |
| const canvas = new OffscreenCanvas( bitmap.width, bitmap.height ); | |
| const ctx = canvas.getContext( '2d' ); | |
| if ( ! ctx ) { | |
| throw new Error( 'Could not get canvas 2d context' ); | |
| } | |
| ctx.drawImage( bitmap, 0, 0 ); | |
| const jpegBlob = await canvas.convertToBlob( { | |
| type: 'image/jpeg', | |
| quality, | |
| } ); | |
| return new File( [ jpegBlob ], `${ baseName }.jpg`, { | |
| type: 'image/jpeg', | |
| } ); | |
| } finally { | |
| bitmap.close(); | |
| } |
A canvas re-encode carries no metadata, so the JPEG that reaches the server has none. The server then reads metadata off whatever file it was handed - WP_REST_Attachments_Controller::insert_attachment() calls wp_read_image_metadata() to default the title, caption and alt text, and wp_generate_attachment_metadata() stores image_meta. Both see an empty file.
Note that this is specific to formats that go through the canvas fallback. JPEG, PNG, WebP and AVIF main files are uploaded byte for byte as the original, so their metadata survives. Sub-size stripping is separate and deliberate - vips is passed keep: 'icc' to match core's image_strip_meta filter, which is the correct behavior.
Steps to reproduce
- Enable client side media processing.
- Take a photo on an iPhone, or use any HEIC that carries an IPTC title, a caption and camera data.
- Upload it into an Image block.
- Open the attachment in the media library and check the title, the caption, and the camera/date details.
Current behavior
Title falls back to the filename, the caption is empty, and image_meta has no camera, credit, copyright, aperture or created_timestamp.
Expected behavior
The same result as a server side HEIC upload: EXIF/IPTC derived title, caption and alt defaults, and a populated image_meta.
Possible approaches
Parse the metadata in the browser before the canvas conversion and send it along with the upload, letting the REST endpoint apply it. This is what swissspidy/media-experiments#314 proposes, and it also opens the door to passing along fields core does not currently surface.
The alternative is to hold on to the source HEIC bytes and have the server read metadata from those. Simpler, but it means uploading the original as well.
Neither is obviously right. The first keeps the work in the browser, which fits the rest of the pipeline, but it needs a metadata parser and a decision about which fields to trust from the client.
Questions
- Should extraction be limited to the fields core already uses (title, caption, alt,
image_meta), or should the endpoint accept the wider set - copyright, aperture, GPS and so on - that Use EXIF metadata for title and caption swissspidy/media-experiments#314 asks about? - Does the same gap apply to the JXL path in Add JPEG XL support #77584, where the client also converts to JPEG before upload?
Related: swissspidy/media-experiments#314
cc: @swissspidy
AI Use
Description written with 🤖 Claude Code.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields✅ Done
Activity
[-]Client side media: EXIF and IPTC metadata is lost when HEIC images are converted before upload[/-][+]Media: EXIF and IPTC metadata is lost when HEIC images are converted by client-side media[/+]adamsilverstein commentedon Aug 25, 2026
Would this work? We need an approach that works when the server lacks HEIC support, wouldn't that mean it would be unable to read the HEIC meta data?