- 
      
- 
        Save javierprovecho/0db63d94373f85c301e6 to your computer and use it in GitHub Desktop. 
    golang png image composition
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package main | |
| // http://blog.golang.org/go-image-package | |
| // http://d.hatena.ne.jp/taknb2nch/20131231/1388500659 | |
| // https://blog.golang.org/go-imagedraw-package | |
| import ( | |
| "flag" | |
| "fmt" | |
| "image" | |
| "image/draw" | |
| "image/png" | |
| "os" | |
| ) | |
| func main() { | |
| flag.Parse() | |
| basename := flag.Arg(0) | |
| overlapname := flag.Arg(1) | |
| ifd_base, err := os.Open(basename) | |
| if err != nil { | |
| fmt.Fprintln(os.Stderr, "not found:"+basename) | |
| os.Exit(1) | |
| } | |
| ifd_overlap, err := os.Open(overlapname) | |
| if err != nil { | |
| fmt.Fprintln(os.Stderr, "not found:"+overlapname) | |
| os.Exit(1) | |
| } | |
| image_base, _ := png.Decode(ifd_base) | |
| image_overlap, _ := png.Decode(ifd_overlap) | |
| // | |
| rect := image_base.Bounds() | |
| point := image.Point{0, 0} | |
| image_rgba := image_base.(*image.RGBA) | |
| draw.Draw(image_rgba, rect, image_overlap, point, 0) | |
| png.Encode(os.Stdout, image_rgba) | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment