gato

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: MIT Imports: 13 Imported by: 0

README

gato

gato is a simple package for image processing operation written in Go

Features

  • Supporting JPG/JPEG and PNG for input image
  • Resize
    • For resizing, there are three interpolation methods available:

Usage

Here's a quick example of how to use gato:

package main

import (
	"fmt"
	"image/jpeg"
	"log"
	"os"

	"github.com/obzva/gato-cli/gato"
)

func main() {
  fileName := "path/your-image.jpg"

  // read image
  img, err := os.Open(fileName)
  if err != nil {
	log.Fatal(err)
  }
  defer img.Close()

  // create a new Data struct
  // pass fileName and io.Reader interface
  data, err := gato.NewData(fileName, img)
  if err != nil {
	log.Fatal(err)
  }

  // create a new Processor struct
  // pass your instructions with Instruction struct
  prc, err := gato.NewProcessor(gato.Instruction{
	Width:         1500,
	Interpolation: gato.NearestNeighbor,
  })
  if err != nil {
    log.Fatal(err)
  }

  // process the image
  res, err := prc.Process(data)
  if err != nil {
	log.Fatal(err)
  }

  // ...
}

Documentation

Index

Constants

View Source
const (
	NearestNeighbor = "nearest-neighbor"
	Bilinear        = "bilinear"
	Bicubic         = "bicubic"
)

Variables

View Source
var (
	ErrInvalidFileName = errors.New("invalid file name")
	ErrInvalidFormat   = errors.New("invalid format: only jpg/jpeg and png formats are supported")
)
View Source
var (
	ErrBilinearSrcImageTooSmall = errors.New("source image is too small: width < 2 or height < 2")
	ErrBicubicSrcImageTooSmall  = errors.New("source image is too small: width < 4 or height < 4")
)
View Source
var (
	ErrInvalidDimension     = errors.New("invalid dimension: one of the dimension is not set or set to 0")
	ErrInvalidInterpolation = errors.New("invalid interpolation method: only nearest-neighbor, bilinear, and bicubic are available")
)

Functions

This section is empty.

Types

type Data

type Data struct {
	Name   string
	Format string
	Image  *image.RGBA
}

Data is a struct that contains the name and format of the image, and the *image.RGBA representation of the image itself.

func NewData

func NewData(fileName string, r io.Reader) (*Data, error)

NewData creates a new Data instance from a file name and a reader. Only jpg/jpeg and png formats are supported. It also creates a new *image.RGBA instance from the reader.

type Instruction

type Instruction struct {
	Width         int
	Height        int
	Interpolation string
}

Instruction is a struct that contains the instruction for the processor.

type Processor

type Processor struct {
	Instruction
	Interpolator interpolator
}

Processor is a struct that contains the instruction and related helpers

func NewProcessor

func NewProcessor(i Instruction) (*Processor, error)

NewProcessor creates a new Processor instance from an Instruction instance. If the Instruction.Width and Instruction.Height are not set, it returns an error ErrInvalidDimension. It also creates a new Interpolator instance from the Interpolation instruction. If Instruction.Interpolation is not set, it defaults to Bilinear.

func (*Processor) Process

func (p *Processor) Process(d *Data) (*image.RGBA, error)

return the processed image following the instructions

Jump to

Keyboard shortcuts

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