pictures

package module
v0.0.0-...-17c44a4 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: MIT Imports: 8 Imported by: 1

README

pictures

Build Status | codecov | Go Report Card | GoDoc

A image tool that allows you to make simple tasks on images.

Support for

  • Resize
  • Crop
If i miss something or you have something interesting, please be part of this project. Let me know! My contact is at the end.

Dependecy Management

Dependency

Project dependencies are managed using Dep. Read more about Dep.

  • Get dependency manager: go get github.com/joaosoft/dependency
  • Install dependencies: dependency get
Go
go get github.com/joaosoft/pictures

Usage

This examples are available in the project at pictures/examples

func main() {
	path := "examples/images"
	fromFolder := fmt.Sprintf("%s/original", path)
	toFolder := fmt.Sprintf("%s/generated", path)

	picture, err := pictures.FromPath(fmt.Sprintf("%s/cat.jpg", fromFolder))
	if err != nil {
		panic(err)
	}

	testResize(picture, fmt.Sprintf("%s/resize", toFolder))
	testCrop(picture, fmt.Sprintf("%s/crop", toFolder))
}

func testResize(picture *pictures.Pictures, toFolder string) {
	fmt.Println("Resize images")

	picture.Resize(2000, 1000)

	picture.ToFile(fmt.Sprintf("%s/cat.png", toFolder), pictures.PNGEncoder())
	picture.ToFile(fmt.Sprintf("%s/cat.bmp", toFolder), pictures.BMPEncoder())
	picture.ToFile(fmt.Sprintf("%s/cat.jpeg", toFolder), pictures.JPEGEncoder(100))
}

func testCrop(picture *pictures.Pictures, toFolder string) {
	fmt.Println("Crop images")

	picture.Crop(0, 0, 1000, 1000)

	picture.ToFile(fmt.Sprintf("%s/cat.png", toFolder), pictures.PNGEncoder())
	picture.ToFile(fmt.Sprintf("%s/cat.bmp", toFolder), pictures.BMPEncoder())
	picture.ToFile(fmt.Sprintf("%s/cat.jpeg", toFolder), pictures.JPEGEncoder(100))
}

Known issues

Follow me at

Facebook: https://www.facebook.com/joaosoft

LinkedIn: https://www.linkedin.com/in/jo%C3%A3o-ribeiro-b2775438/

If you have something to add, please let me know joaosoft@gmail.com

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Encoder

type Encoder func(io.Writer, image.Image) error

func BMPEncoder

func BMPEncoder() Encoder

func JPEGEncoder

func JPEGEncoder(quality int) Encoder

func PNGEncoder

func PNGEncoder() Encoder

type Pictures

type Pictures struct {
	image.Image
}

func FromBytes

func FromBytes(byts []byte) (*Pictures, error)

func FromFile

func FromFile(file *os.File) (*Pictures, error)

func FromPath

func FromPath(filename string) (*Pictures, error)

func (*Pictures) Crop

func (p *Pictures) Crop(x0, y0, x1, y1 int) *Pictures

func (*Pictures) Resize

func (p *Pictures) Resize(width, height int) *Pictures

func (*Pictures) ToBytes

func (p *Pictures) ToBytes(encoder Encoder) ([]byte, error)

func (*Pictures) ToFile

func (p *Pictures) ToFile(filename string, encoder Encoder) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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