From 4c712040735dc786485cc0144b2c5f9012a9d23a Mon Sep 17 00:00:00 2001 From: pine3ree Date: Thu, 19 Jan 2023 10:19:27 -0500 Subject: [PATCH] Add PR #238 allow custom precision float to be returned from Pageimage::ratio() --- wire/core/Pageimage.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wire/core/Pageimage.php b/wire/core/Pageimage.php index 1b1d761d..429c34b3 100644 --- a/wire/core/Pageimage.php +++ b/wire/core/Pageimage.php @@ -1321,16 +1321,17 @@ class Pageimage extends Pagefile { /** * Get ratio of width divided by height * + * @param int $precision Optionally specify a value >2 for custom precision (default=2) 3.0.211+ * @return float * @since 3.0.154 * */ - public function ratio() { + public function ratio($precision = 2) { $width = $this->width(); $height = $this->height(); if($width === $height) return 1.0; $ratio = $width / $height; - $ratio = round($ratio, 2); + $ratio = round($ratio, max(2, (int) $precision)); if($ratio > 99.99) $ratio = 99.99; // max allowed width>height ratio if($ratio < 0.01) $ratio = 0.01; // min allowed height>width ratio return $ratio;