Make WordPress Core

Changes between Version 3 and Version 4 of Ticket #46885, comment 4


Ignore:
Timestamp:
04/13/2019 06:47:37 AM (6 years ago)
Author:
pinktank
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #46885, comment 4

    v3 v4  
    11If you don't mind helping with the the code below, I can add it to the documentation as a comment.
    22
    3 *oops, I borked a double loop for some reason
    4 
    5 {{{
    6 // Parse through array to unset the original src
    7 foreach($sources as $element_width => $element_source) {
    8         if($element_source == $image_src ){
    9             unset($sources[$element_width]);
    10         }
    11 }
    12 // Move largest derivative to first position.
    13 $largest_img_key = max(array_keys($sources));
    14 $sources = array( $largest_img_key => $sources[$largest_img_key]) + $sources;
    15 }}}
     3*edited code in next comment
    164
    175On number 3, what I mean is if you have an image that is off by one px in image ratio due to rounding, this causes the image to jiggle in resizes and get blurry in conditions where the aspect ratio is determined by the original width/height. If a developer could disable the 1px error margin or specify which specific image sizes they want to use, they can choose to only show images that are resized in multiples of 2, say 180w 360w 720w to avoid potential 1px shifts in the dom. I suppose this can again be handled by a loop per above though via white listing, could even be done by checking the modulo of original src / resized src.