imgge

package module
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 License: MIT Imports: 10 Imported by: 1

README

Imgge

Package creates randomized glitch effects that can be applied to images or on consecutive frames for animations. Functions can be created by calling functions such as NewShift or NewPixelSort. All effects made to work with the draw.Image type.

Documentation

pkg.go.dev/github.com/keithroger/imgge

Install

$ go get github.com/keithroger/imgge

Effects

The Effect interface is used to impliment all effects.

type Effect interface {
	// Draws the effect to the image with with the current
    // settings defined by the struct.
	Apply(draw.Image)

	// Next makes small variations to the effect.
	// Use in a sequence of images to produce an animated effect.
	Next()

	// Resets random components of effect.
	Randomize()
}
Shift

Shift Effect

View Example
// Import jpeg using included function
img, err := imgge.JpegToImage("images/original.jpg")
if err != nil {
	log.Fatal(err)
}

// Create and Apply Effect
effect := imgge.NewShift(img.Bounds(), 20, 30, 22)
effect.Apply(img)

// Export to png using included function
err = imgge.SaveAsPng("Shift.png", img)
if err != nil {
	log.Fatal(err)
}
Color Shift

Color Shift

View Example
// Import jpeg using included function
img, err := imgge.JpegToImage("images/original.jpg")
if err != nil {
	log.Fatal(err)
}

// Create and Apply Effect
effect := imgge.NewColorShift(img.Bounds(), 20, 30, 25)
effect.Apply(img)

// Export to png using included function
err = imgge.SaveAsPng("ColorShift.png", img)
if err != nil {
	log.Fatal(err)
}
Pixel Sort

Pixel Sort

View Example
// Import jpeg using included function
img, err := imgge.JpegToImage("images/original.jpg")
if err != nil {
	log.Fatal(err)
}

// Create and Apply Effect
effect := imgge.NewPixelSort(img.Bounds(), 50, 100, "horiz")
effect.Apply(img)

// Export to png using included function
err = imgge.SaveAsPng("PixelSort.png", img)
if err != nil {
	log.Fatal(err)
}
Pixel Pop

Pixel Pop

View Example
// Import jpeg using included function
img, err := imgge.JpegToImage("images/original.jpg")
if err != nil {
	log.Fatal(err)
}

// Create and Apply Effect
effect := imgge.NewPixelPop(img.Bounds(), 15, 50, 100)
effect.Apply(img)

// Export to png using included function
err = imgge.SaveAsPng("PixelPop.png", img)
if err != nil {
	log.Fatal(err)
}

Documentation

Overview

Package applies randomized glitch effects to images. Effects can be applied to individual images or applied in sequences for animatons.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func JpegToImage added in v0.4.3

func JpegToImage(filename string) (draw.Image, error)

func SaveAsPng added in v0.4.3

func SaveAsPng(filename string, img image.Image) error

Types

type ColorShift added in v0.4.0

type ColorShift struct {
	Rect      image.Rectangle
	MaxHeight int
	MaxShift  int
	N         int
	// contains filtered or unexported fields
}

Colorshift represents an effect that moves blocks randomly left and right by shifting color channels.

Example
package main

import (
	"log"

	"github.com/keithroger/imgge"
)

func main() {
	// Import jpeg using included function
	img, err := imgge.JpegToImage("images/original.jpg")
	if err != nil {
		log.Fatal(err)
	}

	// Create and Apply Effect
	effect := imgge.NewColorShift(img.Bounds(), 20, 30, 25)
	effect.Apply(img)

	// Export to png using included function
	err = imgge.SaveAsPng("ColorShift.png", img)
	if err != nil {
		log.Fatal(err)
	}
}
Output:

func NewColorShift added in v0.4.0

func NewColorShift(r image.Rectangle, maxHeight, maxShift, n int) *ColorShift

NewColorShift creates a Colorshift struct. The Effect will be drawn within the rectangle r with shifted blocks max height of maxHeight and max horizontal shift of maxShift.

func (*ColorShift) Apply added in v0.4.0

func (c *ColorShift) Apply(img draw.Image)

Apply shifts sections of the image according to the stucts settings.

func (*ColorShift) Next added in v0.4.3

func (c *ColorShift) Next()

Next makes small random changes to the position of the shifted blocks.

func (*ColorShift) Randomize added in v0.4.0

func (c *ColorShift) Randomize()

Randomize reinitializes the positions of the shifted blocks.

type Effect

type Effect interface {
	// Draws the effect to the image with with the current settings defined by the struct.
	Apply(draw.Image)

	// Next makes small variations to the effect.
	// Use in a sequence of images to produce an animated effect.
	Next()

	// Resets random components of effect.
	Randomize()
}

Effect provides methods for applying effects and randomization.

type PixelPop added in v0.4.0

type PixelPop struct {
	Rect             image.Rectangle
	MinSize, MaxSize int
	N                int
	// contains filtered or unexported fields
}

PixelPop represents an effect that makes random pixels and draws a square of the same color.

Example
package main

import (
	"log"

	"github.com/keithroger/imgge"
)

func main() {
	// Import jpeg using included function
	img, err := imgge.JpegToImage("images/original.jpg")
	if err != nil {
		log.Fatal(err)
	}

	// Create and Apply Effect
	effect := imgge.NewPixelPop(img.Bounds(), 15, 50, 100)
	effect.Apply(img)

	// Export to png using included function
	err = imgge.SaveAsPng("PixelPop.png", img)
	if err != nil {
		log.Fatal(err)
	}
}
Output:

func NewPixelPop added in v0.4.0

func NewPixelPop(r image.Rectangle, minSize, maxSize, n int) *PixelPop

NewPixelPop returns a PixelPop struct.

func (*PixelPop) Apply added in v0.4.0

func (p *PixelPop) Apply(img draw.Image)

Apply selects random pixels in the image and draws them as squares.

func (*PixelPop) Next added in v0.4.3

func (p *PixelPop) Next()

Next makes small random changes to the position of the source pixels.

func (*PixelPop) Randomize added in v0.4.0

func (p *PixelPop) Randomize()

Randomize reinitializes the positions of the shifted blocks.

type PixelSort added in v0.4.0

type PixelSort struct {
	Rect        image.Rectangle
	MaxLen      int
	N           int
	Orientation string
	// contains filtered or unexported fields
}

Pixelsort represents an Effect that moves sorts lines of pixels.

Example
package main

import (
	"log"

	"github.com/keithroger/imgge"
)

func main() {
	// Import jpeg using included function
	img, err := imgge.JpegToImage("images/original.jpg")
	if err != nil {
		log.Fatal(err)
	}

	// Create and Apply Effect
	effect := imgge.NewPixelSort(img.Bounds(), 50, 100, "horiz")
	effect.Apply(img)

	// Export to png using included function
	err = imgge.SaveAsPng("PixelSort.png", img)
	if err != nil {
		log.Fatal(err)
	}
}
Output:

func NewPixelSort added in v0.4.0

func NewPixelSort(r image.Rectangle, maxLen, n int, orientation string) *PixelSort

NewPixelSort returns a new PixelSort Effect.

func (*PixelSort) Apply added in v0.4.0

func (p *PixelSort) Apply(img draw.Image)

Apply sorts pixels according to the PixelSort settings.

func (*PixelSort) Next added in v0.4.3

func (p *PixelSort) Next()

Next makes small random changes to the source point for the PixelSort

func (*PixelSort) Randomize added in v0.4.0

func (p *PixelSort) Randomize()

Randomize reinitializes the positions of the shifted sections.

type Shift added in v0.4.0

type Shift struct {
	Rect      image.Rectangle
	MaxHeight int
	MaxShift  int
	N         int
	// contains filtered or unexported fields
}

Shift represents an effect that moves blocks within the images randomly left or right

Example
package main

import (
	"log"

	"github.com/keithroger/imgge"
)

func main() {
	// Import jpeg using included function
	img, err := imgge.JpegToImage("images/original.jpg")
	if err != nil {
		log.Fatal(err)
	}

	// Create and Apply Effect
	effect := imgge.NewShift(img.Bounds(), 20, 30, 22)
	effect.Apply(img)

	// Export to png using included function
	err = imgge.SaveAsPng("Shift.png", img)
	if err != nil {
		log.Fatal(err)
	}
}
Output:

func NewShift added in v0.4.0

func NewShift(r image.Rectangle, maxHeight, maxShift, n int) *Shift

NewShift creates a Shift struct. The Effect will be drawn within the rectangle r with shifted blocks max height of maxHeight and max horizontal shift of maxShift.

func (*Shift) Apply added in v0.4.0

func (s *Shift) Apply(img draw.Image)

Apply shifts sections of the image according to the Shift settings.

func (*Shift) Next added in v0.4.3

func (s *Shift) Next()

Next makes small random changes to the position of the shifted blocks.

func (*Shift) Randomize added in v0.4.0

func (s *Shift) Randomize()

Randomize reinitializes the positions of the shifted blocks.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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