Skip to content

Commit

Permalink
Use correct ratio when applying image filters to image alternatives (#…
Browse files Browse the repository at this point in the history
…1147)

Because of a previous change, the keys of the image alternatives array
is no longer the ratio, but rather the image width. We now make sure to
calculate the ratio correctly and use the appropriate one when applying
the image filters.
  • Loading branch information
fredrikekelund authored and flaviocopes committed Nov 1, 2016
1 parent 76aed8a commit 58d4e33
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion system/src/Grav/Common/Page/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ public function __construct($path)
$types['alternative'][$i] = MediumFactory::scaledFromMedium($alternatives[$max]['file'], $max, $i);
}

foreach ($types['alternative'] as $ratio => $altMedium) {
foreach ($types['alternative'] as $altMedium) {
if ($altMedium['file'] != $medium) {
$ratio = $altMedium['file']->get('width') / $medium->get('width');
$medium->addAlternative($ratio, $altMedium['file']);
}
}
Expand Down
4 changes: 2 additions & 2 deletions system/src/Grav/Common/Page/Medium/ImageMedium.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ public function __call($method, $args)
try {
call_user_func_array([$this->image, $method], $args);

foreach ($this->alternatives as $ratio => $medium) {
foreach ($this->alternatives as $medium) {
if (!$medium->image) {
$medium->image();
}
Expand All @@ -509,7 +509,7 @@ public function __call($method, $args)
if (isset(self::$magic_resize_actions[$method])) {
foreach (self::$magic_resize_actions[$method] as $param) {
if (isset($args_copy[$param])) {
$args_copy[$param] = (int) $args_copy[$param] * $ratio;
$args_copy[$param] *= $medium->get('ratio');
}
}
}
Expand Down

0 comments on commit 58d4e33

Please sign in to comment.