16

I have the following:

  1. Background image (bi)
  2. Image1 (i1)
  3. Image3 (i2)

I want to position i1 and i2 over bi with some angle and then produce a final image. I have x and y axis value for i1 and i2 and their expected rotation angle. i1 and i2 may partially overlay on each other. but I have z index for i1 and i2 to know, if in case they overlap then who will be in foreground.

I am trying to achieve this in Golang.
http://golang.org/doc/articles/image_draw.html seems to do this. Anyone knows any similar example of code, that may help. Or can you show me couple of lines in Golang as a pseudo program?

Thanks.

JVK
  • 3,782
  • 8
  • 43
  • 67
  • 1
    What have you tried? Do you have a piece of code you wrote but can't make to work? Quick googling told me that rotation is supported in http://code.google.com/p/graphics-go – 9000 Sep 14 '12 at 19:47
  • 1
    graphics-go seems dead . nothing is there – JVK Sep 15 '12 at 00:17
  • @JVK, the last change in the VCS seems to be made yesterday, so it's not dead :) – nemo Sep 15 '12 at 09:13

1 Answers1

40

Not sure exactly what you are looking for and I haven't worked with the image package much at all ... but just following the sample code and using graphics-go package (it works for me), I was able to do something at least.

package main

import (
    "fmt"
    "os"
    "image/draw"
    "image"
    "image/jpeg"
    "code.google.com/p/graphics-go/graphics"
)

func main() {
    fImg1, _ := os.Open("arrow1.jpg")
    defer fImg1.Close()
    img1, _, _ := image.Decode(fImg1)

    fImg2, _ := os.Open("arrow2.jpg")
    defer fImg2.Close()
    img2, _, _ := image.Decode(fImg2)

    m := image.NewRGBA(image.Rect(0, 0, 800, 600))
    draw.Draw(m, m.Bounds(), img1, image.Point{0,0}, draw.Src)
    //draw.Draw(m, m.Bounds(), img2, image.Point{-200,-200}, draw.Src)
    graphics.Rotate(m, img2, &graphics.RotateOptions{3.5})

    toimg, _ := os.Create("new.jpg")
    defer toimg.Close()

    jpeg.Encode(toimg, m, &jpeg.Options{jpeg.DefaultQuality})
}
Deleplace
  • 6,812
  • 5
  • 28
  • 41
sathishvj
  • 1,394
  • 2
  • 17
  • 28
  • @sathish $ go run img.go img.go:9:5: import "code.google.com/p/graphics-go/graphics": cannot find package – JVK Sep 17 '12 at 17:46
  • @Sathish I got the "cannot find package" error sorted out. I have : PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/go/bin PWD=/usr/local/go/pkg OLDPWD=/usr/local/go Logged in as root and went to /usr/local/go/pkg $> cd /usr/local/go/pkg then run $> go get code.google.com/p/graphics-go/graphics $> go install code.google.com/p/graphics-go/graphics Is it right? However I still need to work on image stitching part as output image does nto seem correct. Will keep you updated – JVK Sep 17 '12 at 19:15