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

WordPress Trac noreply at wordpress.org
Sun Oct 23 09:45:45 UTC 2016

#36477: Responsive images (srcset) can include images larger than the full size
 Reporter:  peterdavehello           |       Owner:  joemcgill
     Type:  defect (bug)             |      Status:  accepted
 Priority:  normal                   |   Milestone:  Future Release
Component:  Media                    |     Version:  4.4.2
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:  performance
Changes (by codex-m):

 * keywords:  needs-patch => has-patch needs-testing


 @mikeschroder Here it is. I attached 36477_2.diff. Basically I dig deeper
 into the issue and found out that this only affects indexed-color images.
 These images are limited to 256 colors. And when resized by WordPress,
 additional colors are added. And the image type is then converted from
 indexed color type to RGB true color. This increases the file size.

 I also found out that to eliminate performance issue while checking for
 image colors. Its best to check for image type only using
 `Imagick::getImageType`. This will return if the image is indexed-color
 encoded or RGB.

 The fix is simple, it then checks if the image type is indexed color. If
 yes, retains the image type after saving. This dramatically reduces the
 file size for affected image types while retaining our existing
 filters/quality settings ;)

 In my test, this fix reduces the file size of indexed color images
 resizing to around 50%. This fix also resolves the following existing
 WordPress trac tickets like this:
 https://core.trac.wordpress.org/ticket/30402. It is because after
 resizing, the image type is now retained.

 Let me know what you think. Thanks!

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

More information about the wp-trac mailing list