@@ -30,6 +30,8 @@ class DinImage
3030
3131 private $ intervention ;
3232
33+ private $ watermark = array ();
34+
3335 public function __construct (array $ config = [])
3436 {
3537 $ this ->config = $ config ;
@@ -99,6 +101,21 @@ public function setName($name)
99101 return $ this ;
100102 }
101103
104+ /**
105+ * @param array $watermark
106+ * watermark['src'] - Path completo da imagem
107+ * watermark['position'] - Posição, pode ser:
108+ * top-left (default), top, top-right, left, center, right, bottom-left, bottom, bottom-right
109+ * watermark['x'] - Offset em X
110+ * watermark['y'] - Offset em Y
111+ */
112+ public function setWatermark (array $ watermark )
113+ {
114+ $ this ->watermark = $ watermark ;
115+
116+ return $ this ;
117+ }
118+
102119 public function setImage ($ image_source )
103120 {
104121 $ image_source = urldecode ($ image_source );
@@ -111,7 +128,14 @@ public function setImage($image_source)
111128 $ ext = pathinfo ($ this ->image_source , PATHINFO_EXTENSION );
112129
113130 $ this ->image = $ this ->config ['dest_folder ' ] .
114- $ this ->name . $ this ->getHash () . '. ' . $ ext ;
131+ $ this ->name . $ this ->getHash ();
132+
133+ if (count ($ this ->watermark ))
134+ {
135+ $ this ->image .= 'watermark ' ;
136+ }
137+
138+ $ this ->image .= '. ' . $ ext ;
115139
116140 return $ this ;
117141 }
@@ -135,7 +159,19 @@ public function render()
135159 $ img = $ this ->intervention ->make ($ this ->image_source )->heighten ($ this ->height );
136160 break ;
137161 }
162+
163+ if (count ($ this ->watermark ))
164+ {
165+ $ img ->insert (
166+ $ this ->watermark ['src ' ],
167+ $ this ->watermark ['position ' ],
168+ $ this ->watermark ['x ' ],
169+ $ this ->watermark ['y ' ]
170+ );
171+ }
172+
138173 $ img ->save ($ this ->image , 100 );
174+
139175 }
140176
141177 return $ this ->config ['url ' ] . $ this ->image ;
@@ -147,4 +183,4 @@ private function getHash()
147183 return '- ' . Str::limit ($ hash , 5 , '' );
148184 }
149185
150- }
186+ }
0 commit comments