mirror of
https://github.com/nxshock/colorcrop.git
synced 2025-07-02 00:23:44 +05:00
Move examples to one file
This commit is contained in:
parent
a0a018de16
commit
c7fe0bb79e
3 changed files with 3 additions and 42 deletions
|
@ -39,4 +39,4 @@ croppedImage := colorcrop.CropWithComparator(
|
|||
|
||||
## Examples
|
||||
|
||||
See in "examples".
|
||||
See [here](https://github.com/nxshock/colorcrop/blob/master/example_test.go).
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/nxshock/colorcrop"
|
||||
)
|
||||
|
||||
// Simple remove of white borders.
|
||||
func ExampleCrop() {
|
||||
log.SetFlags(0)
|
||||
|
||||
|
@ -31,6 +32,7 @@ func ExampleCrop() {
|
|||
png.Encode(croppedFile, croppedImage)
|
||||
}
|
||||
|
||||
// Remove white borders with custom color comparator.
|
||||
func ExampleCropWithComparator() {
|
||||
log.SetFlags(0)
|
||||
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
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