image

package module
v0.0.0-...-232a192 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 16 Imported by: 3

README

imagi

read a image and resample it to save

Documentation

Index

Constants

View Source
const (
	MinJPEGQuality = jpeg.DefaultQuality // 75
	MinWebpQuality = 80
)

consts

View Source
const (
	FormatGIF  = "gif"
	FormatJPEG = "jpeg"
	FormatPNG  = "png"
	FormatWEBP = "webp"
)

consts

View Source
const (
	WebpEncodable = true
)

Variables

View Source
var (
	ErrInvalidFormat   = errors.New("invalid image format")
	ErrUnsupportFormat = errors.New("unsupported image format")
	ErrOrigTooSmall    = errors.New("original image too small")
	ErrEmptyImage      = errors.New("image is empty")
)

vars of errors

Functions

func Format2Ext

func Format2Ext(f string) string

Format2Ext ...

func GetPoint

func GetPoint(sm, wm image.Point, pos Position) (pt image.Point)

GetPoint ...

func PatchFormat

func PatchFormat(s string) string

PatchFormat ...

func SaveTo

func SaveTo(w io.Writer, m image.Image, opt *WriteOption) (n int, err error)

SaveTo ...

func Thumbnail

func Thumbnail(r io.Reader, w io.Writer, topt *ThumbOption) error

Thumbnail ...

func ThumbnailFile

func ThumbnailFile(src, dest string, topt *ThumbOption) (err error)

ThumbnailFile ...

func ThumbnailImage

func ThumbnailImage(img image.Image, topt *ThumbOption) (image.Image, error)

ThumbnailImage ...

func ThumbnailImageTo

func ThumbnailImageTo(im image.Image, w io.Writer, topt *ThumbOption) error

ThumbnailImageTo ...

func Watermark

func Watermark(r, wr io.Reader, w io.Writer, wo WaterOption) error

Watermark ...

func WatermarkFile

func WatermarkFile(src, wname, dest string, wo WaterOption) (err error)

WatermarkFile ...

func WatermarkImage

func WatermarkImage(img, water image.Image, pos Position, opacity Opacity) (image.Image, error)

WatermarkImage add a watermark and copyright into a image with position and opacity

Types

type Attr

type Attr struct {
	Width   uint32 `json:"width"`
	Height  uint32 `json:"height"`
	Size    uint32 `json:"size,omitempty"` // Original size
	Quality uint8  `json:"qlt,omitempty"`  // Original quality
	Ext     string `json:"ext"`            // file extension include dot
	Mime    string `json:"mime,omitempty"` // content type
}

Attr ...

func NewAttr

func NewAttr(w, h uint, f string) *Attr

NewAttr ...

func (*Attr) FromMap

func (a *Attr) FromMap(m map[string]any)

FromMap ...

func (Attr) ToMap

func (a Attr) ToMap() map[string]any

ToMap ...

type CountWriter

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

CountWriter ...

func (*CountWriter) Len

func (cw *CountWriter) Len() int

Len return count value

func (*CountWriter) Write

func (cw *CountWriter) Write(p []byte) (n int, err error)

Write implements for io.Writer

type Image

type Image struct {
	*Attr
	Format string
	// contains filtered or unexported fields
}

Image ...

func NewFromImage

func NewFromImage(m image.Image, size int, format string) (*Image, error)

func Open

func Open(rs io.ReadSeeker) (*Image, error)

Open ...

func (*Image) SaveTo

func (im *Image) SaveTo(w io.Writer, opt *WriteOption) (int, error)

SaveTo ...

func (*Image) ThumbnailTo

func (im *Image) ThumbnailTo(w io.Writer, topt *ThumbOption) error

ThumbnailTo ...

type Imager

type Imager interface {
	SaveTo(w io.Writer, opt WriteOption) error
	ThumbnailTo(w io.Writer, topt ThumbOption) error
}

Imager ...

type Opacity

type Opacity uint8

Opacity ...

type Position

type Position uint8

Position ...

const (
	BottomRight Position = iota
	BottomLeft
	TopLeft
	TopRight
	Center
	Golden
)

Position

type ThumbOption

type ThumbOption struct {
	Width, Height       uint // 宽和高
	MaxWidth, MaxHeight uint // 最大宽和高
	IsFit               bool // 是否保持比例
	IsCrop              bool // 是否裁切
	CropX, CropY        int  // 裁切位置

	WriteOption
	// contains filtered or unexported fields
}

ThumbOption 缩图选项

func (ThumbOption) String

func (topt ThumbOption) String() string

type WaterOption

type WaterOption struct {
	Pos      Position
	Opacity  Opacity
	Filename string
	WriteOption
}

WaterOption ...

type WriteOption

type WriteOption struct {
	Format  string
	Quality uint8
}

WriteOption ...

Jump to

Keyboard shortcuts

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