Skip to content
This repository was archived by the owner on Aug 6, 2024. It is now read-only.

linlichieh/img

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

img

Draw a rectangle on an image in Golang

Example

package main

import (
    "github.com/jex-lin/img"
    "bytes"
    "image"
    "image/color"
    "io/ioutil"
    "os"
)

func main() {
    // Load bytes from image file
    src, _ := ioutil.ReadFile("/tmp/gopher.jpg")

    // Create new image file
    t2, _ := os.Create("/tmp/gopher2.jpg")
    defer t2.Close()

    // New Draw struct
    d, _ := img.NewDraw(bytes.NewReader(src))

    // Draw a rectangle with thickness of 3
    b := d.SetColor(color.RGBA{255, 0, 0, 0}).DrawRect(image.Rect(210, 10, 380, 130), 3).OutputBytes()

    // Write bytes into file
    _, _ = t2.Write(b)
}

Source:

Result:

About

Draw a rectangle on an image in Golang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages