From fc5e9d325aafd380e10b1f805ad90c388467378f Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Thu, 18 Apr 2024 16:34:29 +0530 Subject: [PATCH] Fix division by zero in Rgb toCmyk method --- src/Renderer/Color/Rgb.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Renderer/Color/Rgb.php b/src/Renderer/Color/Rgb.php index 6dcb632..9e388da 100644 --- a/src/Renderer/Color/Rgb.php +++ b/src/Renderer/Color/Rgb.php @@ -54,6 +54,10 @@ public function toCmyk() : Cmyk $y = 1 - ($this->blue / 255); $k = min($c, $m, $y); + if ($k === 0) { + return new Cmyk(0, 0, 0, 0); + } + return new Cmyk( (int) (100 * ($c - $k) / (1 - $k)), (int) (100 * ($m - $k) / (1 - $k)),