Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageMedium#derivatives now works with image filters #1107

Merged
merged 10 commits into from
Oct 23, 2016
Prev Previous commit
Next Next commit
Modified initialization of image alternatives
The biggest alternative will now become the base medium, and
alternatives will be filled out as necessary in a descending
manner.
  • Loading branch information
fredrikekelund committed Sep 12, 2016
commit c2e6292f13bff82d80d2c474d0e23fcba02bb78f
19 changes: 8 additions & 11 deletions system/src/Grav/Common/Page/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,12 @@ public function __construct($path)
}

// Create the base medium
if (!empty($types['base'])) {
if (empty($types['base'])) {
$max = max(array_keys($types['alternative']));
$medium = $types['alternative'][$max]['file'];
} else {
$medium = MediumFactory::fromFile($types['base']['file']);
$medium && $medium->set('size', $types['base']['size']);
} else if (!empty($types['alternative'])) {
$altMedium = reset($types['alternative']);
$ratio = key($types['alternative']);

$altMedium = $altMedium['file'];

$medium = MediumFactory::scaledFromMedium($altMedium, $ratio, 1)['file'];
}

if (empty($medium)) {
Expand All @@ -103,10 +99,9 @@ public function __construct($path)
// Build missing alternatives
if (!empty($types['alternative'])) {
$alternatives = $types['alternative'];

$max = max(array_keys($alternatives));

for ($i=2; $i < $max; $i++) {
for ($i=$max; $i > 0; $i--) {
if (isset($alternatives[$i])) {
continue;
}
Expand All @@ -115,7 +110,9 @@ public function __construct($path)
}

foreach ($types['alternative'] as $ratio => $altMedium) {
$medium->addAlternative($ratio, $altMedium['file']);
if ($altMedium['file'] != $medium) {
$medium->addAlternative($ratio, $altMedium['file']);
}
}
}

Expand Down