imageconvert

package
v2.7.2 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ImageExtensionRegex = regexp.MustCompile(".*.jpg$|.*.jpeg$|.*.png$|.*.webp$|.*.JPG$|.*.JPEG$|.*.PNG$|.*.WEBP$")

ImageExtensionRegex captures file extensions we can work with.

View Source
var NilTime = time.Time{}

NilTime is 0

View Source
var RenameSuffixRegex = regexp.MustCompile(".*.jpeg$|.*.png$|.*.webp$|.*.JPG$|.*.JPEG$|.*.PNG$|.*.WEBP$")

RenameExtensionRegex captures file extensions that we would like to rename to the extensions above.

Functions

This section is empty.

Types

type ConversionResult

type ConversionResult struct {
	OriginalFileName  string
	ConvertedFileName string
	ImageType         string
	CompressOutput    string
	Error             error
	Compressed        bool
	Renamed           bool
	Resized           bool
}

ConversionResult is all the information about the image that was converted.

type ImageConverter

type ImageConverter struct {
	Compress              bool
	Force                 bool
	Watch                 bool
	ResizeWidth           uint16
	ResizeWidthThreshold  uint16
	ResizeHeight          uint16
	ResizeHeightThreshold uint16
	Threads               uint8
	InputEntry            path.Entry
	InputFiles            []path.Entry
	SkipMapEntry          path.Entry
	SkipMap               map[string]struct{}
	humantime.TimeRange
	ShutdownTrigger   chan struct{}
	ShutdownCompleted []chan struct{}
}

ImageConverter is the main config

func NewWithDefaults

func NewWithDefaults(inputPath, skipFile string, directoryDepth uint8) (ImageConverter, error)

NewWithDefaults returns a new ImageConverter with conservative defaults. Use the WithX() functions to further configure.

func (*ImageConverter) ParseSkipMap

func (ic *ImageConverter) ParseSkipMap() (map[string]struct{}, error)

ParseSkipMap reads the log from the last time this was run and puts those filenames in a map so we dont have to process them again If you want to reprocess, just delete the file.

func (*ImageConverter) Shutdown

func (ic *ImageConverter) Shutdown()

Shutdown gracefully closes all chans and quits.

func (*ImageConverter) Start

func (ic *ImageConverter) Start(results chan ConversionResult) (int, int, int, int, map[string]int, error)

Start begins the conversion process and returns counts of each type of operation preformed.

func (*ImageConverter) WithCompression

func (ic *ImageConverter) WithCompression()

WithCompression will compress the images.

func (*ImageConverter) WithForce

func (ic *ImageConverter) WithForce()

WithForce will process files even if there are present in the skip file.

func (*ImageConverter) WithResize

func (ic *ImageConverter) WithResize(width, height, widthThreshold, heightThreshold uint16)

WithResize resizes images down to a size given by width X height greater than a threshold given by widthThreshold X heightThreshold.

func (*ImageConverter) WithThreads

func (ic *ImageConverter) WithThreads(threads uint8)

WithThreads specifies the number of CPU threads to use. The default is one but increacing this will significaltny improve performance epsically when compressing images. Pass a positive number of threads you wish to use, if 0 is passed, num cores - 1 will be set.

func (*ImageConverter) WithTimeRange

func (ic *ImageConverter) WithTimeRange(tr humantime.TimeRange)

WithTimeRange will set a time range within images must have been last modified in order to be considered for processing.

func (*ImageConverter) WithWatch

func (ic *ImageConverter) WithWatch()

WithWatch enables watching a directory for new or modified files.

type TimeOfEntry

type TimeOfEntry struct {
	path.WatchEvent
	time.Time
}

TimeOfEntry is a wrapper struct for waitTilFileWritesComplete

Jump to

Keyboard shortcuts

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