From a83642a7e3fea3cbe5c2879a724c883eed4e4a68 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Thu, 12 Nov 2015 19:15:26 +0100 Subject: [PATCH] Added a higherQualityAlternative () method to get the highest quality image available (3x or 2x) --- .../Grav/Common/Page/Medium/ImageMedium.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index 329fcce91..85e3d63b6 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -516,4 +516,28 @@ class ImageMedium extends Medium $this->__call($method, $params); } } + + /** + * Return the image higher quality version + * + * @return ImageMedium the alternative version with higher quality + */ + public function higherQualityAlternative() + { + if ($this->alternatives) { + $max = reset($this->alternatives); + foreach($this->alternatives as $alternative) + { + if($alternative->quality() > $max->quality()) + { + $max = $alternative; + } + } + + return $max; + } else { + return $this; + } + } + }