@@ -138,7 +138,7 @@ public function getBoundingBox(): BoundingBox
138138     * @see https://github.com/DantSu/php-image-editor See more about DantSu\PHPImageEditor\Image 
139139     * @return Image An instance of DantSu\PHPImageEditor\Image 
140140     */ 
141-     public  function  getMapImage (): Image 
141+     protected  function  getMapImage (): Image 
142142    {
143143        $ bbox  = $ this  ->boundingBox ;
144144        $ xTile  = static ::lngToXTile ($ bbox ->getBottomLeft ()->getLng (), $ this  ->zoom );
@@ -164,6 +164,35 @@ public function getMapImage(): Image
164164        return  $ image ;
165165    }
166166
167+     /** 
168+      * Draw OpenStreetMap attribution at the right bottom of the image 
169+      * @param Image $image The image of the map 
170+      * @return Image The image of the map with attribution 
171+      */ 
172+     protected  function  drawAttribution (Image   $ image ): Image 
173+     {
174+         $ margin  = 5 ;
175+         $ attribution  = function  (Image   $ image , $ margin ): array  {
176+             return  $ image ->writeTextAndGetBoundingBox (
177+                 '© OpenStreetMap contributors ' ,
178+                 __DIR__  . '/resources/font.ttf ' ,
179+                 10 ,
180+                 '0078A8 ' ,
181+                 $ margin ,
182+                 $ margin ,
183+                 Image::ALIGN_LEFT ,
184+                 Image::ALIGN_TOP 
185+             );
186+         };
187+ 
188+         $ bbox  = $ attribution (Image::newCanvas (1 , 1 ), $ margin );
189+         $ imageAttribution  = Image::newCanvas ($ bbox ['bottom-right ' ]['x ' ] + $ margin , $ bbox ['bottom-right ' ]['y ' ] + $ margin );
190+         $ imageAttribution ->drawRectangle (0 , 0 , $ imageAttribution ->getWidth (), $ imageAttribution ->getHeight (), 'FFFFFF33 ' );
191+         $ attribution ($ imageAttribution , $ margin );
192+ 
193+         return  $ image ->pasteOn ($ imageAttribution , Image::ALIGN_RIGHT , Image::ALIGN_BOTTOM );
194+     }
195+ 
167196    /** 
168197     * Get the map image with markers and lines. 
169198     * 
@@ -182,6 +211,6 @@ public function getImage(): Image
182211            $ markers ->draw ($ image , $ this  ->boundingBox );
183212        }
184213
185-         return  $ image ;
214+         return  $ this -> drawAttribution ( $ image) ;
186215    }
187216}
0 commit comments