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
Set better prettynames for image derivatives
  • Loading branch information
fredrikekelund committed Oct 16, 2016
commit 91cea78a84b6dd50d9dba2dda315de4b638ab58e
16 changes: 13 additions & 3 deletions system/src/Grav/Common/Page/Medium/ImageMedium.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,22 @@ public function derivatives($min_width, $max_width, $step = 200) {
// original image file no longer exists and this class instance was
// retrieved from the page cache
if (isset($derivative)) {
$ratio = $base->get('width') / $width;
$height = $derivative->get('height') / $ratio;
$index = 2;
$widths = array_keys($this->alternatives);
sort($widths);

foreach ($widths as $i => $key) {
if ($width > $key) {
$index += max($i, 1);
}
}

$basename = preg_replace('/(@\d+x)*$/', "@{$ratio}x", $base->get('basename'), 1);
$basename = preg_replace('/(@\d+x)*$/', "@{$index}x", $base->get('basename'), 1);
$derivative->setImagePrettyName($basename);

$ratio = $base->get('width') / $width;
$height = $derivative->get('height') / $ratio;

$derivative->resize($width, $height);
$derivative->set('width', $width);
$derivative->set('height', $height);
Expand Down