Test rework, bugfixes and more tests

This commit is contained in:
nxshock 2017-06-26 23:12:48 +05:00
parent 1cf1415b29
commit 28d09be6b5
22 changed files with 240 additions and 45 deletions

View file

@ -1,3 +1,6 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package colorcrop_test
import (
@ -9,7 +12,7 @@ import (
"github.com/nxshock/colorcrop"
)
func Example() {
func ExampleBasicUsage() {
log.SetFlags(0)
// Read source image
@ -18,8 +21,34 @@ func Example() {
sourceImage, _ := png.Decode(sourceFile)
// Crop image white border with 50% thresold
croppedImage := colorcrop.Crop(sourceImage, color.RGBA{255, 255, 255, 255}, 0.5)
// Crop white border with 50% thresold
croppedImage := colorcrop.Crop(
sourceImage, // for source image
color.RGBA{255, 255, 255, 255}, // crop white border
0.5) // with 50% thresold
// Save cropped image
croppedFile, _ := os.Create("cropped.png")
defer croppedFile.Close()
png.Encode(croppedFile, croppedImage)
}
func ExampleCustomComparator() {
log.SetFlags(0)
// Read source image
sourceFile, _ := os.Open("img.png")
defer sourceFile.Close()
sourceImage, _ := png.Decode(sourceFile)
// Crop white border with 50% thresold
croppedImage := colorcrop.CropWithComparator(
sourceImage, // for source image
color.RGBA{255, 255, 255, 255}, // crop white border
0.5, // with 50% thresold
colorcrop.CmpCIE76) // using CIE76 standart for defining color difference
// Save cropped image
croppedFile, _ := os.Create("cropped.png")