gopic

package module
v0.0.0-...-445e921 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: GPL-3.0 Imports: 13 Imported by: 0

README

goPic package

I was fed up with Golang's photo-processing abilities, so I wrote goPic!It's like the PIL package in Python!

How To Install

go get -u github.com/jiayuqi7813/gopic

Example

package main

import (
	"fmt"
	"image/color"
	"github.com/jiayuqi7813/gopic"
)

func main() {
	filep := "j.png"
	pic := gopic.ImageFile(filep)
	w, h := pic.Size()
	fmt.Println(pic.Mode())
	newpic := gopic.NewPicFile(w, h, color.Palette{color.RGBA{}})
	for i := 0; i < w; i++ {
		for j := 0; j < h; j++ {
			rgb := pic.GetPixel(i, j)
			newpic.PutPixel(i, j, color.Palette{color.NRGBA{R: uint8(rgb[0]), G: uint8(rgb[1]), B: uint8(rgb[2]), A: 255}})
		}
	}
	newpic.Show()
}

image-20220814163819684

Welcome to use, and welcome to put forward issues, help our goPic better and better

License

GPL3.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ImageTypes = map[ImageType]string{
	JPEG:   "jpeg",
	PNG:    "png",
	WEBP:   "webp",
	TIFF:   "tiff",
	GIF:    "gif",
	PDF:    "pdf",
	SVG:    "svg",
	MAGICK: "magick",
	HEIF:   "heif",
	AVIF:   "avif",
}

ImageTypes stores as pairs of image types supported and its alias names.

Functions

func FileOpen

func FileOpen(filename string) (*os.File, error)

FileOpen Open the file and determine the type according to the suffix

func GetCMYKpicColor

func GetCMYKpicColor(file *PicFile, x, y int) []int

GetCMYKpicColor returns CMYK of the pixel at (x, y).Not Alpha

func GetGraypicColor

func GetGraypicColor(file *PicFile, x, y int) []int

GetGraypicColor returns Gray of the pixel at (x, y).Not Alpha

func GetRGBpicColor

func GetRGBpicColor(file *PicFile, x, y int) []int

GetRGBpicColor returns RGB of the pixel at (x, y).Not Alpha

func GetYcbcrpicColor

func GetYcbcrpicColor(file *PicFile, x, y int) []int

GetYcbcrpicColor returns YCbCr of the pixel at (x, y).Not Alpha

Types

type ImageType

type ImageType int

ImageType represents an image type value.

const (
	// UNKNOWN represents an unknow image type value.
	UNKNOWN ImageType = iota
	// JPEG represents the JPEG image type.
	JPEG
	// WEBP represents the WEBP image type.
	WEBP
	// PNG represents the PNG image type.
	PNG
	// TIFF represents the TIFF image type.
	TIFF
	// GIF represents the GIF image type.
	GIF
	// PDF represents the PDF type.
	PDF
	// SVG represents the SVG image type.
	SVG
	// MAGICK represents the libmagick compatible genetic image type.
	MAGICK
	// HEIF represents the HEIC/HEIF/HVEC image type
	HEIF
	// AVIF represents the AVIF image type.
	AVIF
)

func ImgType

func ImgType(filename string) ImageType

ImgType returns the image type of the given filename.

type NewPic

type NewPic struct {
	// contains filtered or unexported fields
}

func NewPicFile

func NewPicFile(width, height int, palette color.Palette) *NewPic

NewPicFile returns a new PicFile.

func (*NewPic) Img2Array

func (p *NewPic) Img2Array() [][][3]float32

Img2Array convert image to array

func (*NewPic) PutPixel

func (p *NewPic) PutPixel(x, y int, palette color.Palette)

PutPixel puts the pixel at (x, y) to the image.

func (*NewPic) Resize

func (p *NewPic) Resize(width, height int) *PicFile

func (*NewPic) Save

func (p *NewPic) Save(file string)

Save saves the image to file.

func (*NewPic) Show

func (p *NewPic) Show()

Show shows the image.

type PicFile

type PicFile struct {
	// contains filtered or unexported fields
}

func ImageFile

func ImageFile(filename string) *PicFile

ImageFile Import the image and determine the type according to the suffix only jpg or png

func (*PicFile) Format

func (p *PicFile) Format() string

Format returns the format of the image.

func (*PicFile) GetPixel

func (p *PicFile) GetPixel(x, y int) []int

GetPixel returns RGB of the pixel at (x, y).Not Alpha

func (*PicFile) Img2Array

func (p *PicFile) Img2Array() [][][3]float32

Img2Array convert image to array

func (*PicFile) ImgSplit

func (p *PicFile) ImgSplit() (r, g, b *NewPic)

ImgSplit Split the image into r,g,b channels

func (*PicFile) Mode

func (p *PicFile) Mode() string

Mode returns the mode of the image.

func (*PicFile) Resize

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

Resize resizes the image to the specified width and height.

func (*PicFile) Save

func (p *PicFile) Save(file string)

Save saves the image to file.

func (*PicFile) Show

func (p *PicFile) Show()

Show shows the image.

func (*PicFile) Size

func (p *PicFile) Size() (int, int)

Size returns the size of the image.

Jump to

Keyboard shortcuts

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