Skip to content

Commit

Permalink
Merge pull request #5 from justbetter/feature/fix-fit-config
Browse files Browse the repository at this point in the history
Use right config
  • Loading branch information
BobWez98 authored Sep 25, 2024
2 parents 05f6559 + 2225ec8 commit f6b09e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
26 changes: 13 additions & 13 deletions config/glide-directive.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
// The default presets used for generating the resizes.
// If the config in statamic.assets.image_manipulation.presets is empty this will be used instead.
'presets' => [
'placeholder' => ['w' => 32, 'h' => 32, 'q' => 100, 'fit' => 'crop_focal'],
'xs' => ['w' => 320, 'h' => 320, 'q' => 100, 'fit' => 'crop_focal'],
'sm' => ['w' => 480, 'h' => 480, 'q' => 100, 'fit' => 'crop_focal'],
'md' => ['w' => 768, 'h' => 768, 'q' => 100, 'fit' => 'crop_focal'],
'lg' => ['w' => 1280, 'h' => 1280, 'q' => 100, 'fit' => 'crop_focal'],
'xl' => ['w' => 1440, 'h' => 1440, 'q' => 100, 'fit' => 'crop_focal'],
'2xl' => ['w' => 1680, 'h' => 1680, 'q' => 100, 'fit' => 'crop_focal'],
'placeholder' => ['w' => 32, 'h' => 32, 'q' => 100, 'fit' => 'contain'],
'xs' => ['w' => 320, 'h' => 320, 'q' => 100, 'fit' => 'contain'],
'sm' => ['w' => 480, 'h' => 480, 'q' => 100, 'fit' => 'contain'],
'md' => ['w' => 768, 'h' => 768, 'q' => 100, 'fit' => 'contain'],
'lg' => ['w' => 1280, 'h' => 1280, 'q' => 100, 'fit' => 'contain'],
'xl' => ['w' => 1440, 'h' => 1440, 'q' => 100, 'fit' => 'contain'],
'2xl' => ['w' => 1680, 'h' => 1680, 'q' => 100, 'fit' => 'contain'],

'xs-h' => ['w' => 160, 'h' => 320, 'q' => 100, 'fit' => 'crop_focal'],
'sm-h' => ['w' => 320, 'h' => 480, 'q' => 100, 'fit' => 'crop_focal'],
'md-h' => ['w' => 480, 'h' => 768, 'q' => 100, 'fit' => 'crop_focal'],
'lg-h' => ['w' => 768, 'h' => 1280, 'q' => 100, 'fit' => 'crop_focal'],
'xl-h' => ['w' => 1280, 'h' => 1440, 'q' => 100, 'fit' => 'crop_focal'],
'2xl-h' => ['w' => 1440, 'h' => 1680, 'q' => 100, 'fit' => 'crop_focal'],
'xs-h' => ['w' => 160, 'h' => 320, 'q' => 100, 'fit' => 'contain'],
'sm-h' => ['w' => 320, 'h' => 480, 'q' => 100, 'fit' => 'contain'],
'md-h' => ['w' => 480, 'h' => 768, 'q' => 100, 'fit' => 'contain'],
'lg-h' => ['w' => 768, 'h' => 1280, 'q' => 100, 'fit' => 'contain'],
'xl-h' => ['w' => 1280, 'h' => 1440, 'q' => 100, 'fit' => 'contain'],
'2xl-h' => ['w' => 1440, 'h' => 1680, 'q' => 100, 'fit' => 'contain'],
],

// Configure which sources you would like to use.
Expand Down
11 changes: 6 additions & 5 deletions src/Responsive.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,32 @@ public static function getPresets(Asset $image): array
}

$configPresets = self::getPresetsByRatio($image, $config);

$imageMeta = $image->meta();
$fit = isset($imageMeta['data']['focus']) ? sprintf('crop-%s', $imageMeta['data']['focus']) : null;
$index = 0;
foreach ($configPresets as $preset => $data) {
$size = $data['w'].'w';

if ($index < (count($configPresets) - 1)) {
$size .= ', ';
}

if (self::canUseWebpSource()) {
$glideUrl = Statamic::tag($preset === 'placeholder' ? 'glide:data_url' : 'glide')->params(['preset' => $preset, 'src' => $image->url(), 'format' => 'webp', 'fit' => $data['crop'] ?? 'crop_focal'])->fetch();
$glideUrl = Statamic::tag($preset === 'placeholder' ? 'glide:data_url' : 'glide')->params(['preset' => $preset, 'src' => $image->url(), 'format' => 'webp', 'fit' => $fit ?? $data['fit']])->fetch();
if ($glideUrl) {
$presets['webp'] .= $glideUrl.' '.$size;
}
}

if (self::canUseMimeTypeSource()) {
$glideUrl = Statamic::tag($preset === 'placeholder' ? 'glide:data_url' : 'glide')->params(['preset' => $preset, 'src' => $image->url(), 'fit' => $data['crop'] ?? 'crop_focal'])->fetch();
$glideUrl = Statamic::tag($preset === 'placeholder' ? 'glide:data_url' : 'glide')->params(['preset' => $preset, 'src' => $image->url(), 'fit' => $fit ?? $data['fit']])->fetch();
if ($glideUrl) {
$presets[$image->mimeType()] .= $glideUrl.' '.$size;
}
}

if ($preset === 'placeholder') {
$glideUrl = Statamic::tag('glide:data_url')->params(['preset' => 'placeholder', 'src' => $image->url(), 'fit' => $data['crop'] ?? 'crop_focal'])->fetch();
$glideUrl = Statamic::tag('glide:data_url')->params(['preset' => 'placeholder', 'src' => $image->url(), 'fit' => $fit ?? $data['fit']])->fetch();
if ($glideUrl) {
$presets['placeholder'] = $glideUrl;
}
Expand Down

0 comments on commit f6b09e5

Please sign in to comment.