[wp-trac] [WordPress Trac] #34955: The choices of images to add to srcset shouldn't be via a ratio

WordPress Trac noreply at wordpress.org
Wed Dec 9 23:38:04 UTC 2015


#34955: The choices of images to add to srcset shouldn't be via a ratio
-------------------------+-----------------------------
 Reporter:  smerriman    |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Media        |    Version:  4.4
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 In #34810:

   As the difference between the widths being compared increases, the
 probability that rounding will introduce false positives also grows. We
 could make the aspect ratio variance we allow relative to the difference
 between the widths we're comparing, but the extra calculation is probably
 unnecessary unless the difference between image widths is in the tens of
 thousands.

 This is not quite true. The issue does not arise when serving huge images
 with tens of thousands of pixels difference - but when serving small
 images.

 Suppose I upload a 768x1055 image. The default 300x300 medium thumbnail
 will be 218x300, which differs in ratio by just over 0.002, thus will not
 be added to the srcset.

 Given 1/0.002 = 500, any image over 500px wide will never cause an issue,
 and with most mobiles etc being retina, you could argue this will never
 occur. However, there are still cases where you would want it - eg non
 retina desktop screens where an image jumps from a large version for some
 screen sizes to a small version for another.

 Rather than checking if |b/a - d/c|<0.002, checking if |b - d*c/a|<=1 will
 ensure images are allowed if the resulting height will differ by no more
 than 1 pixel, which seems a better approach.

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


More information about the wp-trac mailing list