[wp-trac] [WordPress Trac] #62900: PNG original image not affected by conversion filter

WordPress Trac noreply at wordpress.org
Mon Feb 3 14:39:24 UTC 2025


#62900: PNG original image not affected by conversion filter
--------------------------+-----------------------------
 Reporter:  pixlpirate    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  6.7.1
 Severity:  normal        |   Keywords:  needs-patch
  Focuses:                |
--------------------------+-----------------------------
 **Filter used**:
 {{{#!php
 <?php

 add_filter('image_editor_output_format', function( $formats ) {
     $formats['image/png'] = 'image/avif';

     return $formats;
 });
 }}}

 **To reproduce**:
 1. Add the following filter to `functions.php`
 2. Upload a PNG image, e.g. **image.png**
 3. Note that the sub-sizes of **image.png** are converted to AVIF (if
 any), but original image remains in PNG

 **Expected behavior**:
 - The original image should be converted

 ----

 **Possible cause**
 This issue may come from line //265// of the `wp-admin/includes/image.php`
 At this point, PNG images are skipped before checking the defined output
 format.

 {{{#!php
 <?php

 // Do not scale (large) PNG images. May result in sub-sizes that have
 greater file size than the original. See #48736.
 if ( 'image/png' !== $imagesize['mime'] ) {
 ...
 }
 }}}

 A possible fix could be
 {{{#!php
 <?php

 // Get output format if image needs to be converted
 $output_format = wp_get_image_editor_output_format( $file,
 $imagesize['mime'] );

 // Do not scale (large) PNG images. May result in sub-sizes that have
 greater file size than the original. See #48736.
 if ( 'image/png' !== $output_format ) {
 ...
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62900>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list