mirror of
https://github.com/nxshock/colorcrop.git
synced 2025-07-03 00:33:44 +05:00
Upload code
This commit is contained in:
parent
b055be1d8e
commit
602c4b0993
6 changed files with 227 additions and 1 deletions
41
example/main.go
Normal file
41
example/main.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"image/png"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/nxshock/colorcrop"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
|
||||
// Read source image
|
||||
sourceFile, err := os.Open("img.png")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer sourceFile.Close()
|
||||
|
||||
sourceImage, err := png.Decode(sourceFile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
// Crop image white border with 50% thresold
|
||||
croppedImage := colorcrop.Crop(sourceImage, color.RGBA{255, 255, 255, 255}, 0.5)
|
||||
|
||||
// Save cropped image
|
||||
croppedFile, err := os.Create("cropped.png")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer croppedFile.Close()
|
||||
|
||||
err = png.Encode(croppedFile, croppedImage)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue