Skip to content

Commit

Permalink
Fix for generated srcset where the size being requested isn't a defin…
Browse files Browse the repository at this point in the history
…ed size.
  • Loading branch information
jawngee committed Oct 31, 2018
1 parent 86eff4e commit ecb5c31
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
10 changes: 8 additions & 2 deletions classes/Tools/Imgix/ImgixTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ private function buildImgixImage($id, $size, $params = null, $skipParams = false
}
}

if($sizeInfo['crop']) {
if(isset($sizeInfo['crop'])) {
$params['w'] = $sizeInfo['width'] ?: $sizeInfo['height'];
$params['h'] = $sizeInfo['height'] ?: $sizeInfo['width'];
$params['fit'] = 'crop';
Expand Down Expand Up @@ -631,7 +631,13 @@ private function buildImgixImage($id, $size, $params = null, $skipParams = false
unset($params['fp-z']);
}
} else {
$newSize = sizeToFitSize($meta['width'], $meta['height'], $sizeInfo['width'] ?: 10000, $sizeInfo['height'] ?: 10000);
$mw = (isset($meta['width'])) ? $meta['width'] : 10000;
$mh = (isset($meta['height'])) ? $meta['height'] : 10000;

$w = (isset($sizeInfo['width'])) ? $sizeInfo['width'] : 10000;
$h = (isset($sizeInfo['height'])) ? $sizeInfo['height'] : 10000;

$newSize = sizeToFitSize($mw, $mh, $w, $h);
$params['w'] = $newSize[0];
$params['h'] = $newSize[1];
$params['fit'] = 'scale';
Expand Down
23 changes: 15 additions & 8 deletions classes/Tools/Storage/StorageTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,16 +715,23 @@ public function calculateSrcSet($sources, $size_array, $image_src, $image_meta,
return $sources;
}

$allSizes = ilab_get_image_sizes();
$allSizesNames = array_keys($allSizes);

foreach($image_meta['sizes'] as $sizeName => $sizeData) {
$width = $sizeData['width'];
if(isset($sources[$width])) {
$src = wp_get_attachment_image_src($attachment_id, $sizeName);

if(is_array($src)) {
$sources[$width]['url'] = $src[0];
} else {
unset($sources[$width]);
}
if (isset($sources[$width])) {
if (in_array($sizeName, $allSizesNames)) {
$src = wp_get_attachment_image_src($attachment_id, $sizeName);

if(is_array($src)) {
$sources[$width]['url'] = $src[0];
} else {
unset($sources[$width]);
}
} else {
unset($sources[$width]);
}
}
}

Expand Down

0 comments on commit ecb5c31

Please sign in to comment.