Added a higherQualityAlternative () method to get the highest quality image available (3x or 2x)

This commit is contained in:
Flavio Copes
2015-11-12 19:15:26 +01:00
parent 00d8403095
commit a83642a7e3

View File

@@ -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;
}
}
}