imgrz

package
v0.0.0-...-ef729d8 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// input extract
	ErrGetLocalDirImages = 21
	ErrOpenLocalImage    = 22
	ErrOpenHttpImage     = 23
	// filter
	ErrDetectName = 30
	ErrDetectSize = 31
	// resize handle
	ErrResize = 40
)

Resize Error

View Source
const (
	M byteSize
	G
	T
	P
)

Growth based on human-readable unit formats, 1k=1024b,1M=1024k..

Variables

This section is empty.

Functions

func GetFmtBasename

func GetFmtBasename(basename, format string) string

GetFmtBasename get the new image basename based on the specified target image format and the name of the original image

func GetImagesFromDir

func GetImagesFromDir(dirname string) ([]string, error)

GetImagesFromDir gets slice of the image file and iterates through the selected directory and its subdirectories.

func HumDS2Bytes

func HumDS2Bytes(size string) (len uint64, err error)

HumDS2Bytes parse human data size(like 10k,10M) to bytes unit length, like 1k = 1024bytes

func HumDSLimit

func HumDSLimit(size string, limit string) (bool, error)

HumDSLimit compare human data sizes and limit setting (like find -size). Param size and limit both support human data size format(bytes, kilobytes, megabytes), like 100k, 1M

HumDSLimit("2000", "+1k") represent whether 1000 bytes >= 1*1024 bytes

+/-: >= or < , 1k: 1k=1024bytes

Types

type Category

type Category int
const (
	Local Category = iota
	Http
)

type Error

type Error struct {
	No   int
	Mark string
	Msg  string
}

func NewError

func NewError(no int, mark, msg string) Error

new goimgrz error

func (Error) Error

func (e Error) Error() string

type Filter

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

Filter is an filter pick up the image matching the condition

func NewFilter

func NewFilter(pattern, size string) *Filter

Create an filter

func (*Filter) DetectName

func (f *Filter) DetectName(image Image) (bool, error)

DetectName check the input url or image file whether match the filter pattern

func (*Filter) DetectSize

func (f *Filter) DetectSize(image Image) (bool, error)

DetectSize check the input url

type Image

type Image interface {
	// SetResize set image resizing setting property, used for image resize
	SetResize(setting *Setting)

	// DoResize fit the specified resizing configuration resize image to destination
	// Fit the specified scaling configuration (such as size, interpolation function, path, quality),
	// perform image scaling, return the path of the scaled image, or any errors in the scaling process
	DoResize() (string, error)
}

Image support using specified parameters resize image to dst

func NewImage

func NewImage(cate Category, ident string) Image

New create an image for a specific category

type LocImage

type LocImage struct {
	Filename string
	Setting  *Setting
}

LocImage is an local image file whose image from local filesystem

func (*LocImage) DoResize

func (img *LocImage) DoResize() (save string, err error)

func (*LocImage) SetResize

func (img *LocImage) SetResize(setting *Setting)

SetResize add image resizing property

type Setting

type Setting struct {
	Dst           string
	Width, Height uint
	Interp        uint
	Qty           int
	Format        string
}

Setting is image resize property setting like width,height,interp,quality,format

type Task

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

Task used for collect image resize, dispatching resize image task, got the save result or fail info from channel

func NewTask

func NewTask(setting *Setting) *Task

NewTask create an GirTas pointer

func (*Task) Add

func (gt *Task) Add(image Image) *Task

Add use filtering information to filter files, and add image to task for resizing

func (*Task) AddImg

func (gt *Task) AddImg(img string) *Task

AddImg add local image file to task, waiting for resize

func (*Task) AddImgs

func (gt *Task) AddImgs(imgs string) *Task

AddImgs add multiple image file to task, waiting for resize

func (*Task) AddScanDir

func (gt *Task) AddScanDir(dir string) *Task

AddDirname specified dirname, scan images and add it to gir task, waiting for resize

func (*Task) AddUrl

func (gt *Task) AddUrl(url string) *Task

AddUrl add web image url to task, waiting for resize

func (*Task) AddUrls

func (gt *Task) AddUrls(urls string) *Task

AddUrls add multiple image url to task, waiting for resize

func (*Task) EmptyTask

func (gt *Task) EmptyTask() bool

EmptyTask return Task whether is empty

func (*Task) Filter

func (gt *Task) Filter(image Image) error

Filter filter specified image

func (*Task) Report

func (gt *Task) Report()

Report synchronously report success or fail result in background, when gir task is finish

func (*Task) Run

func (gt *Task) Run()

ResizeImages concurrency resize image in it's GirImage slice

func (*Task) SetFilter

func (gt *Task) SetFilter(f *Filter) *Task

SetFilter setting the task filter, using for filter no match info

func (*Task) SetVerbose

func (gt *Task) SetVerbose(v bool) *Task

SetVerbose setting the task show detail message

type WebImage

type WebImage struct {
	Url     string
	Setting *Setting
	// contains filtered or unexported fields
}

WebImage is an image from http(s) url

func (*WebImage) DoResize

func (img *WebImage) DoResize() (save string, err error)

func (*WebImage) SetClient

func (img *WebImage) SetClient(client *http.Client) *WebImage

SetClient add http client for web image

func (*WebImage) SetResize

func (img *WebImage) SetResize(setting *Setting)

Jump to

Keyboard shortcuts

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