edgingo

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2025 License: MPL-2.0 Imports: 3 Imported by: 0

README

Edgingo

Edgingo is a Go library for detecting and removing solid-colored edges/borders from images. It supports removing edges from all sides, vertical edges only, horizontal edges only, or individual sides.

Features

  • Remove edges from all sides of an image
  • Remove only vertical edges (top/bottom)
  • Remove only horizontal edges (left/right)
  • Remove edges from specific sides
  • Aggressive mode that uses a 10% threshold for edge detection
  • Preserves image quality by working with RGBA images

Installation

go get github.com/coalaura/edgingo

Usage

As a Library
import "github.com/coalaura/edgingo"

// Load your image
img, _ := png.Decode(file)

// Convert to RGBA if needed
rgba := edgingo.AsRGBA(img)

// Remove all edges
result := edgingo.RemoveAllEdges(rgba, false)

// Remove only vertical edges
result = edgingo.RemoveVerticalEdges(rgba, false)

// Remove only horizontal edges
result = edgingo.RemoveHorizontalEdges(rgba, false)

// Remove specific edge
result = edgingo.RemoveEdge(rgba, edgingo.SideTop, false)

// Use aggressive mode (10% threshold)
result = edgingo.RemoveAllEdges(rgba, true)

The second parameter aggressive determines whether to use a 10% threshold when detecting edges. When true, it will ignore checking the middle 80% of pixels along each edge.

Command Line Tool

The library includes a command-line tool that can process images directly. It supports PNG, JPEG, and WebP formats.

Installation:

go install github.com/coalaura/edgingo/cmd

Usage:

edgingo <input-image> <output-image>

The CLI tool automatically:

  • Uses aggressive mode for better edge detection
  • Detects the output format based on file extension (.png, .jpg/.jpeg, or .webp)
  • Preserves quality (90% for JPEG, lossless for WebP)

Example:

edgingo input.png output.png

Example

Example of removing all edges from an image with aggressive mode enabled.

Before After
before after

License

See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsRGBA

func AsRGBA(img image.Image) *image.RGBA

AsRGBA converts an image to an RGBA image

func RemoveAllEdges

func RemoveAllEdges(rgba *image.RGBA, aggressive bool) *image.RGBA

func RemoveEdge

func RemoveEdge(rgba *image.RGBA, side ImageSide, aggressive bool) *image.RGBA

func RemoveEdges

func RemoveEdges(rgba *image.RGBA, sides []ImageSide, aggressive bool) *image.RGBA

func RemoveHorizontalEdges

func RemoveHorizontalEdges(rgba *image.RGBA, aggressive bool) *image.RGBA

func RemoveVerticalEdges

func RemoveVerticalEdges(rgba *image.RGBA, aggressive bool) *image.RGBA

func WalkBottomToTop

func WalkBottomToTop(rgba *image.RGBA, cmp CompareFunc, width, height, acceptable int) (edge int)

func WalkLeftToRight

func WalkLeftToRight(rgba *image.RGBA, cmp CompareFunc, width, height, acceptable int) (edge int)

func WalkRightToLeft

func WalkRightToLeft(rgba *image.RGBA, cmp CompareFunc, width, height, acceptable int) (edge int)

func WalkTopToBottom

func WalkTopToBottom(rgba *image.RGBA, cmp CompareFunc, width, height, acceptable int) (edge int)

Types

type CompareFunc

type CompareFunc func(int, int) bool

type ImageSide

type ImageSide int
const (
	SideTop ImageSide = iota
	SideBottom
	SideLeft
	SideRight
)

type Stencil

type Stencil struct {
	Top    int
	Bottom int
	Left   int
	Right  int
}

func NewStencil

func NewStencil() *Stencil

func (*Stencil) Cut

func (s *Stencil) Cut(rgba *image.RGBA, width, height int) *image.RGBA

func (*Stencil) Set

func (s *Stencil) Set(side ImageSide, value int)

type WalkerFunc

type WalkerFunc func(*image.RGBA, CompareFunc, int, int, int) int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL