mirror of
https://github.com/nxshock/colorcrop.git
synced 2025-07-02 00:23:44 +05:00
29 lines
539 B
Go
29 lines
539 B
Go
package colorcrop_test
|
|
|
|
import (
|
|
"image/color"
|
|
"image/png"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/nxshock/colorcrop"
|
|
)
|
|
|
|
func Example() {
|
|
log.SetFlags(0)
|
|
|
|
// Read source image
|
|
sourceFile, _ := os.Open("img.png")
|
|
defer sourceFile.Close()
|
|
|
|
sourceImage, _ := png.Decode(sourceFile)
|
|
|
|
// Crop image white border with 50% thresold
|
|
croppedImage := colorcrop.Crop(sourceImage, color.RGBA{255, 255, 255, 255}, 0.5)
|
|
|
|
// Save cropped image
|
|
croppedFile, _ := os.Create("cropped.png")
|
|
defer croppedFile.Close()
|
|
|
|
png.Encode(croppedFile, croppedImage)
|
|
}
|