From 14534297a2b4f29562de1275a5653055eaf7561b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82?= Date: Sun, 3 Dec 2023 15:09:35 +0100 Subject: [PATCH] Allow usage of Image instance directly Sometimes we need to path an actual ready to go image to markers, for example when we need to downscale them first. This PR allows users to do so, and supports backwards compatibility and fallback to building an image fromPath if the provided parameter is not an Image already. --- src/Markers.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Markers.php b/src/Markers.php index 87f8654..be7d0e9 100644 --- a/src/Markers.php +++ b/src/Markers.php @@ -39,9 +39,19 @@ class Markers */ private $coordinates = []; - public function __construct($pathImage) + /** + * Markers constructor. + * + * @param string|Image $image Path to the image or an instance of Image + */ + public function __construct($image) { - $this->image = Image::fromPath($pathImage); + // If the pathImage is already an instance of Image, we use it directly + if ($image instanceof Image) { + $this->image = $image; + } else { + $this->image = Image::fromPath($image); + } } /**