Commit 22baca24ca for wordpress.org

commit 22baca24caadca8c9e0545125aa8f87a58d661bf
Author: adamsilverstein <adamsilverstein@git.wordpress.org>
Date:   Thu Dec 3 21:25:57 2026 +0000

    Media: Ensure GD converts palette PNGs to WebP and AVIF.

    Fix an issue where converting a palette-based PNG to WebP or AVIF with `WP_Image_Editor_GD` failed with "Palette image not supported by webp" and wrote an empty file, for example when `image_editor_output_format` maps PNG to WebP. GD can only encode truecolor images to these formats, so palette images are now converted to truecolor before saving, with alpha preserved. The converted files are still much smaller than the PNG. Other output formats and truecolor images are unchanged.

    The same fix shipped in the Modern Image Formats plugin, see https://github.com/WordPress/performance/pull/2024.

    Props b1ink0, ozgursar.
    Fixes #63773.


    Built from https://develop.svn.wordpress.org/trunk@65904


    git-svn-id: http://core.svn.wordpress.org/trunk@64933 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/class-wp-image-editor-gd.php b/wp-includes/class-wp-image-editor-gd.php
index 10eed8178b..560420fd18 100644
--- a/wp-includes/class-wp-image-editor-gd.php
+++ b/wp-includes/class-wp-image-editor-gd.php
@@ -559,6 +559,17 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
 			imageinterlace( $image, apply_filters( 'image_save_progressive', false, $mime_type ) );
 		}

+		// Ensure GD can handle WebP/AVIF output of palette based images.
+		if (
+			in_array( $mime_type, array( 'image/webp', 'image/avif' ), true ) &&
+			! imageistruecolor( $image )
+		) {
+			// Preserve transparence and prepare for conversion.
+			imagealphablending( $image, false );
+			imagesavealpha( $image, true );
+			imagepalettetotruecolor( $image );
+		}
+
 		if ( 'image/gif' === $mime_type ) {
 			if ( ! $this->make_image( $filename, 'imagegif', array( $image, $filename ) ) ) {
 				return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) );
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 138555e875..1f908da7c5 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.3-alpha-65901';
+$wp_version = '7.3-alpha-65904';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.