Skip to content

Commit f9d0b5e

Browse files
author
Daniel Byron
committed
Added imageOverlay option to draw icons and images over the top of generated wallpaper
1 parent 34e23bc commit f9d0b5e

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

image.go

+23-5
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,26 @@ func colorsFromImage(filename string) ([]color.Color, error) {
146146

147147
func imageFromColors(colors []color.Color, w int, h int) (image.Image, error) {
148148
rand.Seed(time.Now().UnixNano())
149+
var img image.Image
149150
switch *imageOutType {
150151
case "random":
151-
return randomImage(colors, w, h), nil
152+
img = randomImage(colors, w, h)
152153
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)
154155
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)
156157
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+
}
158162

163+
if *imageOverlay != "" {
164+
overlay := loadImage(*imageOverlay)
165+
img = overlayImage(img, overlay, img.Bounds().Max.X/2, img.Bounds().Max.Y/2)
159166
}
160-
return nil, errors.New("Unrecognised ouput image type: " + *imageOutType + "\n")
167+
168+
return img, nil
161169
}
162170

163171
type Circle struct {
@@ -376,3 +384,13 @@ func randomImage(colors []color.Color, w int, h int) image.Image {
376384
}
377385
return nil
378386
}
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+
}

main.go

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var (
2828
imageWidth *int
2929
imageHeight *int
3030
imageOutType *string // Eg, "random", "circles", "stripes", etc...
31+
imageOverlay *string
3132

3233
// Circles image output options
3334
circlesSize *int
@@ -112,6 +113,7 @@ func main() {
112113
imageOutTypeDesc += "\n"
113114
}
114115
imageOutType = flag.String("imageOutType", "random", imageOutTypeDesc)
116+
imageOverlay = flag.String("imageOverlay", "", "Filename of image to draw on top of generated image (OS/Distro logo, etc...)")
115117

116118
// Circles image output options
117119
circlesSize = flag.Int("circlesSize", 100, "Size of circles in output image")

0 commit comments

Comments
 (0)