@@ -146,18 +146,26 @@ func colorsFromImage(filename string) ([]color.Color, error) {
146
146
147
147
func imageFromColors (colors []color.Color , w int , h int ) (image.Image , error ) {
148
148
rand .Seed (time .Now ().UnixNano ())
149
+ var img image.Image
149
150
switch * imageOutType {
150
151
case "random" :
151
- return randomImage (colors , w , h ), nil
152
+ img = randomImage (colors , w , h )
152
153
case "circles" :
153
- return Circles (colors , w , h , * circlesSize , * circlesSizeVariance , * circlesOverlap , * circlesDrawLargestToSmallest , * circlesFilled , * circlesBorderSize , * circlesBlur , * circlesOpacity ), nil
154
+ img = Circles (colors , w , h , * circlesSize , * circlesSizeVariance , * circlesOverlap , * circlesDrawLargestToSmallest , * circlesFilled , * circlesBorderSize , * circlesBlur , * circlesOpacity )
154
155
case "rays" :
155
- return Rays (colors , w , h , * raysSize , * raysSizeVariance , * raysDistributeEvenly , * raysCentered , * raysDrawLargestToSmallest ), nil
156
+ img = Rays (colors , w , h , * raysSize , * raysSizeVariance , * raysDistributeEvenly , * raysCentered , * raysDrawLargestToSmallest )
156
157
case "stripes" :
157
- return Lines (colors , w , h , * stripesSize , * stripesSizeVariance , * stripesHorizontal , * stripesEvenSpacing , * stripesSpacing , * stripesOffset ), nil
158
+ img = Lines (colors , w , h , * stripesSize , * stripesSizeVariance , * stripesHorizontal , * stripesEvenSpacing , * stripesSpacing , * stripesOffset )
159
+ default :
160
+ return nil , errors .New ("Unrecognised ouput image type: " + * imageOutType + "\n " )
161
+ }
158
162
163
+ if * imageOverlay != "" {
164
+ overlay := loadImage (* imageOverlay )
165
+ img = overlayImage (img , overlay , img .Bounds ().Max .X / 2 , img .Bounds ().Max .Y / 2 )
159
166
}
160
- return nil , errors .New ("Unrecognised ouput image type: " + * imageOutType + "\n " )
167
+
168
+ return img , nil
161
169
}
162
170
163
171
type Circle struct {
@@ -376,3 +384,13 @@ func randomImage(colors []color.Color, w int, h int) image.Image {
376
384
}
377
385
return nil
378
386
}
387
+
388
+ func overlayImage (back image.Image , front image.Image , x int , y int ) image.Image {
389
+ img := image .NewNRGBA (back .Bounds ())
390
+ draw .Draw (img , img .Bounds (), back , image.Point {0 , 0 }, draw .Over )
391
+ frontWidth := front .Bounds ().Max .X
392
+ frontHeight := front .Bounds ().Max .Y
393
+ dst := image .Rect (x - frontWidth / 2 , y - frontHeight / 2 , x + frontWidth / 2 , x + frontHeight / 2 )
394
+ draw .Draw (img , dst , front , image.Point {0 , 0 }, draw .Over )
395
+ return img
396
+ }
0 commit comments