Skip to content

Strip image metadata on upload

By default, image metadata is not stripped from images uploaded to the VIP File System. The strip=all|info|color query parameter can be added to images in order to remove JPEG image Exif, IPTC, comment, and color data from the image when it is output in a browser.

Metadata stripping via VIP’s file service transforms

You can leverage VIP’s own file service to do the work server-side.

  • On upload, the code requests the just-uploaded image back from the file service with ?strip=info appended to its URL.
  • The file service processes the transform and returns the clean image.
  • The code then overwrites the original file with this stripped version.

Here is the code that you can place in a plugin file in your /client-mu-plugins directory:

<?php

add_filter( 'wp_handle_upload', 'yourprefix_strip_metadata_via_transform' );

/**
 * Strip image metadata on upload using VIP's file service transforms.
 *
 * Instead of processing images in PHP via Gmagick/GD, this leverages
 * VIP's file service to strip metadata server-side by:
 * 1. Requesting the just-uploaded image back with ?strip=info
 * 2. Overwriting the original with the stripped version
 *
 * Benefits over Gmagick approach:
 * - No Gmagick/GD/Imagick dependency
 * - No vip:// stream wrapper compatibility issues
 * - Lighter on PHP threads (image processing happens on VIP's file service)
 * - Can handle larger files than GD
 *
 * strip=info removes EXIF, IPTC, and comment metadata while preserving
 * ICC color profiles — exactly matching the Gmagick code behavior.
 *
 * @see https://docs.wpvip.com/vip-file-system/image-files/transformations/query-parameters/
 *
 * @param array $upload {
 *     @type string $file The path to the image file (vip:// on VIP Platform).
 *     @type string $url  The public URL to the image.
 *     @type string $type The MIME type of the image.
 * }
 * @return array Unmodified $upload array.
 */

function yourprefix_strip_metadata_via_transform( array $upload ): array {
    // Only process supported image types.
    if ( ! in_array( $upload['type'], array( 'image/jpeg', 'image/png', 'image/gif' ), true ) ) {
        return $upload;
    }

    // Only run on VIP environments where the file service handles transforms.
    if ( ! defined( 'WPCOM_IS_VIP_ENV' ) || ! WPCOM_IS_VIP_ENV ) {
        return $upload;
    }

    // Build the URL with strip=info parameter.
    // strip=info: strips EXIF, IPTC, comments but preserves ICC color profiles.
    $stripped_url = add_query_arg( 'strip', 'info', $upload['url'] );

    // Fetch the stripped version from VIP's file service.
    // The file service does the image processing — PHP just waits for the response.
    $response = wp_remote_get( $stripped_url, array(
        'timeout' => 30,
    ) );

    if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
        // Transform request failed — return original upload unchanged.
        // The image keeps its metadata but the upload isn't blocked.
        return $upload;
    }

    $stripped_image = wp_remote_retrieve_body( $response );

    if ( empty( $stripped_image ) ) {
        return $upload;
    }

    // Overwrite the original file with the stripped version.
    // file_put_contents() understands the vip:// stream wrapper.
    file_put_contents( $upload['file'], $stripped_image );

    // Purge VIP edge cache for this URL since the file content changed.
    if ( function_exists( 'wpcom_vip_purge_edge_cache_for_url' ) ) {
        wpcom_vip_purge_edge_cache_for_url( $upload['url'] );
    }

    return $upload;
}

How ?strip=info works:

VIP’s file service supports on-the-fly image transformations via query parameters appended to any /wp-content/uploads/ URL. The strip parameter accepts three values:

  • strip=all → All data is stripped, with any existing orientation data being first applied to the image.
  • strip=info → All non-essential EXIF metadata is stripped; color metadata is preserved. We use this one.
  • strip=color → Only EXIF color data is stripped.

For example, if an uploaded image lives at https://example.com/wp-content/uploads/2026/04/photo.jpg, requesting it as https://example.com/wp-content/uploads/2026/04/photo.jpg?strip=info returns the same image with all EXIF/IPTC/comment data removed but colors intact.

Last updated: July 02, 2026

Relevant to

  • WordPress