aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Byron <=>2015-07-22 13:25:47 +1000
committerDaniel Byron <=>2015-07-22 13:27:33 +1000
commitf9d0b5e700be7c9d14acb66ad99a9d40a5a60701 (patch)
treeef6cf11c4569b3cbc16489bbbe0b9d9a815ea4d7
parentUpdate README.md (diff)
downloadschemer2-f9d0b5e700be7c9d14acb66ad99a9d40a5a60701.tar.xz
schemer2-f9d0b5e700be7c9d14acb66ad99a9d40a5a60701.zip
Added imageOverlay option to draw icons and images over the top of generated wallpaper
-rw-r--r--image.go28
-rw-r--r--main.go2
2 files changed, 25 insertions, 5 deletions
diff --git a/image.go b/image.go
index 689103c..9db7ce6 100644
--- a/image.go
+++ b/image.go
@@ -146,18 +146,26 @@ func colorsFromImage(filename string) ([]color.Color, error) {
func imageFromColors(colors []color.Color, w int, h int) (image.Image, error) {
rand.Seed(time.Now().UnixNano())
+ var img image.Image
switch *imageOutType {
case "random":
- return randomImage(colors, w, h), nil
+ img = randomImage(colors, w, h)
case "circles":
- return Circles(colors, w, h, *circlesSize, *circlesSizeVariance, *circlesOverlap, *circlesDrawLargestToSmallest, *circlesFilled, *circlesBorderSize, *circlesBlur, *circlesOpacity), nil
+ img = Circles(colors, w, h, *circlesSize, *circlesSizeVariance, *circlesOverlap, *circlesDrawLargestToSmallest, *circlesFilled, *circlesBorderSize, *circlesBlur, *circlesOpacity)
case "rays":
- return Rays(colors, w, h, *raysSize, *raysSizeVariance, *raysDistributeEvenly, *raysCentered, *raysDrawLargestToSmallest), nil
+ img = Rays(colors, w, h, *raysSize, *raysSizeVariance, *raysDistributeEvenly, *raysCentered, *raysDrawLargestToSmallest)
case "stripes":
- return Lines(colors, w, h, *stripesSize, *stripesSizeVariance, *stripesHorizontal, *stripesEvenSpacing, *stripesSpacing, *stripesOffset), nil
+ img = Lines(colors, w, h, *stripesSize, *stripesSizeVariance, *stripesHorizontal, *stripesEvenSpacing, *stripesSpacing, *stripesOffset)
+ default:
+ return nil, errors.New("Unrecognised ouput image type: " + *imageOutType + "\n")
+ }
+ if *imageOverlay != "" {
+ overlay := loadImage(*imageOverlay)
+ img = overlayImage(img, overlay, img.Bounds().Max.X/2, img.Bounds().Max.Y/2)
}
- return nil, errors.New("Unrecognised ouput image type: " + *imageOutType + "\n")
+
+ return img, nil
}
type Circle struct {
@@ -376,3 +384,13 @@ func randomImage(colors []color.Color, w int, h int) image.Image {
}
return nil
}
+
+func overlayImage(back image.Image, front image.Image, x int, y int) image.Image {
+ img := image.NewNRGBA(back.Bounds())
+ draw.Draw(img, img.Bounds(), back, image.Point{0, 0}, draw.Over)
+ frontWidth := front.Bounds().Max.X
+ frontHeight := front.Bounds().Max.Y
+ dst := image.Rect(x-frontWidth/2, y-frontHeight/2, x+frontWidth/2, x+frontHeight/2)
+ draw.Draw(img, dst, front, image.Point{0, 0}, draw.Over)
+ return img
+}
diff --git a/main.go b/main.go
index 00bc911..8ae1e34 100644
--- a/main.go
+++ b/main.go
@@ -28,6 +28,7 @@ var (
imageWidth *int
imageHeight *int
imageOutType *string // Eg, "random", "circles", "stripes", etc...
+ imageOverlay *string
// Circles image output options
circlesSize *int
@@ -112,6 +113,7 @@ func main() {
imageOutTypeDesc += "\n"
}
imageOutType = flag.String("imageOutType", "random", imageOutTypeDesc)
+ imageOverlay = flag.String("imageOverlay", "", "Filename of image to draw on top of generated image (OS/Distro logo, etc...)")
// Circles image output options
circlesSize = flag.Int("circlesSize", 100, "Size of circles in output image")