[wp-trac] [WordPress Trac] #36477: Responsive images (srcset) can include images larger than the full size

WordPress Trac noreply at wordpress.org
Thu May 16 20:40:29 UTC 2024


#36477: Responsive images (srcset) can include images larger than the full size
-------------------------------------------------+-------------------------
 Reporter:  peterdavehello                       |       Owner:  pbearne
     Type:  defect (bug)                         |      Status:  assigned
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Media                                |     Version:  4.4.2
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-testing dev-         |     Focuses:
  feedback has-unit-tests                        |  performance
-------------------------------------------------+-------------------------

Comment (by nosilver4u):

 Well, I went ahead and asked for ideas on the Imagemagick discussion
 board, and the closest we got was this:

 {{{#!php
 <?php
 $colors = min( 255, $this->image->getImageColors() );
 $this->image->thresholdImage( .5, imagick::CHANNEL_ALPHA );
 $this->image->quantizeImage( $colors, $this->image->getColorspace(), 0,
 false, false );
 }}}

 Which worked fine for deskcat8.png, but I tried it with another PNG8 that
 had transparency, and it put random dots in a grid across the whole image.
 They thought perhaps the deskcat8.png image just had a weird (hidden?)
 black background that was the source of the issues. I'm not certain how
 that is possible, but I'm no expert on the PNG spec.

 At any rate, the quantizeImage() method is probably the best route
 forward, given that it solves the file size issues across all my test
 images and only has a small amount of degradation on that one image.

 I'd recommend doing something a bit more dynamic than the existing patch
 though, and checking the pixel depth via
 https://www.php.net/manual/en/imagick.getimagedepth.php
 Then one can limit the colors based on the depth:
 depth 8: 256 colors
 depth 4: 16 colors
 depth 2: 4 colors
 depth 1: 2 colors

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/36477#comment:54>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list