mirror of
https://github.com/nxshock/colorcrop.git
synced 2025-07-02 00:23:44 +05:00
Upload code
This commit is contained in:
parent
b055be1d8e
commit
602c4b0993
6 changed files with 227 additions and 1 deletions
29
example_test.go
Normal file
29
example_test.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue