Skip to content

Commit

Permalink
refactor: normalize behavior of target widths
Browse files Browse the repository at this point in the history
  • Loading branch information
ericdeansanchez committed May 8, 2020
1 parent 8019f1b commit 32a81a8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Imgix/UrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,17 @@ public function createSrcSet($path, $params=array(), $start=100, $stop=8192, $to
* @return int[] $resolutions An array of even integer values.
*/
public function targetWidths($start=100, $stop=8192, $tol=8) {
$resolutions = array();

$ensureEven = function($n) {
return intval(2 * round($n / 2.0));
};

if ($start == $stop) {
return array($ensureEven($start));
}

$resolutions = array();

while ($start < $stop && $start < 8192) {
array_push($resolutions, $ensureEven($start));
$start *= 1 + ($tol / 100.0) * 2;
Expand Down

0 comments on commit 32a81a8

Please sign in to comment.