A Go library for cropping images by removing borders with specified color.
Find a file
2021-03-23 23:39:31 +05:00
testimages Test rework, bugfixes and more tests 2017-06-26 23:12:48 +05:00
.gitignore Initial commit 2017-06-23 19:14:52 +05:00
.travis.yml Some code reformat for removing long lines 2017-07-03 22:24:47 +05:00
colorconversion.go Test rework, bugfixes and more tests 2017-06-26 23:12:48 +05:00
colorconverson_test.go Some code reformat for removing long lines 2017-07-03 22:24:47 +05:00
colorcrop.go Comparator rework and fixes 2017-06-25 16:52:58 +05:00
colorcrop_test.go Some code reformat for removing long lines 2017-07-03 22:24:47 +05:00
comparators.go Test rework, bugfixes and more tests 2017-06-26 23:12:48 +05:00
comparators_test.go Some code reformat for removing long lines 2017-07-03 22:24:47 +05:00
example_test.go Go fmt 2021-03-23 23:36:27 +05:00
go.mod Add Go modules support 2021-03-23 23:39:31 +05:00
LICENSE Initial commit 2017-06-23 19:14:52 +05:00
README.rst Add Go Report Card bage 2017-08-22 19:24:36 +05:00

colorcrop
=========

|bs| |cs| |rc| |gd|

.. |bs| image:: https://travis-ci.org/nxshock/colorcrop.svg?branch=master
   :alt: Build Status
   :target: https://travis-ci.org/nxshock/colorcrop
.. |cs| image:: https://coveralls.io/repos/github/nxshock/colorcrop/badge.svg
   :alt: Coverage Status
   :target: https://coveralls.io/github/nxshock/colorcrop
.. |rc| image:: https://goreportcard.com/badge/github.com/nxshock/colorcrop
   :alt: Go Report Card Status
   :target: https://goreportcard.com/report/github.com/nxshock/colorcrop
.. |gd| image:: https://godoc.org/github.com/nxshock/colorcrop?status.svg
   :alt: GoDoc
   :target: https://godoc.org/github.com/nxshock/colorcrop

A pure Go library for cropping images by removing borders with specified color.

Installation
------------

``go get -u github.com/nxshock/colorcrop``

Usage
-----

Import package with:

.. code:: go

    import "github.com/nxshock/colorcrop"

Crop white borders with 50% of thresold:

.. code:: go

    croppedImage := colorcrop.Crop(
        sourceImage,                    // for source image
        color.RGBA{255, 255, 255, 255}, // crop white border
        0.5)                            // with 50% thresold

You may use custom comparator of colors:

.. code:: go

    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

List of available comparators:

================  =============================================================================================================
Comparator        Description
================  =============================================================================================================
CmpRGBComponents  simple RGB components difference: ``abs(r1-r2)+abs(g1-g2)+abs(b1-b2)`` (default);
CmpEuclidean      `Euclidean difference <https://en.wikipedia.org/wiki/Color_difference#Euclidean>`_;
CmpCIE76          difference of two colors defined in `CIE76 standard <https://en.wikipedia.org/wiki/Color_difference#CIE76>`_.
================  =============================================================================================================

Examples
--------

See `here <https://github.com/nxshock/colorcrop/blob/master/example_test.go>`_.