Skip to content

Media: EXIF and IPTC metadata is lost when HEIC images are converted by client-side media #82033

Closed

Description

@adamsilverstein

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 (

export const CLIENT_SIDE_SUPPORTED_MIME_TYPES: readonly string[] = [
'image/jpeg',
'image/png',
'image/gif',
'image/webp',
'image/avif',
] as const;
), so prepareItem() routes it to the canvas fallback:
} 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:

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

  1. Enable client side media processing.
  2. Take a photo on an iPhone, or use any HEIC that carries an IPTC title, a caption and camera data.
  3. Upload it into an Image block.
  4. 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

Related: swissspidy/media-experiments#314

cc: @swissspidy

AI Use

Description written with 🤖 Claude Code.

Activity

  1. added
    [Type] Bug
    [Feature] Media
    [Feature] Client Side Media
    on Aug 25, 2026
  2. changed the title [-]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[/+] on Aug 25, 2026
  3. adamsilverstein commented on Aug 25, 2026

    @adamsilverstein
    MemberAuthor

    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.

    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?

  4. added
    [Status] In Progress
    on Aug 25, 2026
  5. moved this from 🏗️ In Progress to ✅ Done in WordPress 7.2 Editor Taskson Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

[Feature] Client Side Media[Feature] Media[Status] In Progress[Type] Bug

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions