Documentation
¶
Index ¶
- Constants
- Variables
- type Blob
- func NewBlob(newReader func() (reader io.ReadCloser, size int64, err error)) *Blob
- func NewBlobFromBytes(buf []byte) *Blob
- func NewBlobFromFile(filepath string, checks ...func(os.FileInfo) error) *Blob
- func NewBlobFromJsonMarshal(v any) *Blob
- func NewBlobFromMemory(buf []byte, width, height, bands int) *Blob
- func NewEmptyBlob() *Blob
- func (b *Blob) BlobType() BlobType
- func (b *Blob) ContentType() string
- func (b *Blob) Err() error
- func (b *Blob) FilePath() string
- func (b *Blob) IsEmpty() bool
- func (b *Blob) IsRaw() bool
- func (b *Blob) Memory() (data []byte, width, height, bands int, ok bool)
- func (b *Blob) NewReadSeeker() (io.ReadSeekCloser, int64, error)
- func (b *Blob) NewReader() (reader io.ReadCloser, size int64, err error)
- func (b *Blob) ReadAll() ([]byte, error)
- func (b *Blob) Release() error
- func (b *Blob) SetContentType(contentType string)
- func (b *Blob) Size() int64
- func (b *Blob) Sniff() []byte
- func (b *Blob) SupportsAnimation() bool
- type BlobType
- type Cacher
- type Detector
- type DetectorAdder
- type DetectorRegion
- type ErrForward
- type Error
- type Imagor
- func (app *Imagor) Do(r *http.Request, p imagorpath.Params) (blob *Blob, err error)
- func (app *Imagor) Serve(ctx context.Context, p imagorpath.Params) (*Blob, error)
- func (app *Imagor) ServeBlob(ctx context.Context, blob *Blob, p imagorpath.Params) (*Blob, error)
- func (app *Imagor) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (app *Imagor) Shutdown(ctx context.Context) (err error)
- func (app *Imagor) Startup(ctx context.Context) (err error)
- type LoadFunc
- type Loader
- type Option
- func WithAutoAVIF(enable bool) Option
- func WithAutoJPEG(enable bool) Option
- func WithAutoWebP(enable bool) Option
- func WithBaseParams(params string) Option
- func WithBasePathRedirect(url string) Option
- func WithCacheHeaderNoCache(nocache bool) Option
- func WithCacheHeaderSWR(swr time.Duration) Option
- func WithCacheHeaderTTL(ttl time.Duration) Option
- func WithDebug(debug bool) Option
- func WithDetector(d Detector) Option
- func WithDetectors(ds ...Detector) Option
- func WithDisableErrorBody(disabled bool) Option
- func WithDisableParamsEndpoint(disabled bool) Option
- func WithEnablePostRequests(enable bool) Option
- func WithGetResultKey(fn func(*http.Request, imagorpath.Params) string) Option
- func WithGetSigner(fn func(*http.Request) imagorpath.Signer) Option
- func WithLoadTimeout(timeout time.Duration) Option
- func WithLoaders(loaders ...Loader) Option
- func WithLogger(logger *zap.Logger) Option
- func WithModifiedTimeCheck(enabled bool) Option
- func WithOptions(options ...Option) Option
- func WithProcessConcurrency(concurrency int64) Option
- func WithProcessQueueSize(size int64) Option
- func WithProcessTimeout(timeout time.Duration) Option
- func WithProcessors(processors ...Processor) Option
- func WithRequestTimeout(timeout time.Duration) Option
- func WithResponseRawOnError(enabled bool) Option
- func WithResultStoragePathStyle(hasher imagorpath.ResultStorageHasher) Option
- func WithResultStorages(savers ...Storage) Option
- func WithSaveTimeout(timeout time.Duration) Option
- func WithSigner(signer imagorpath.Signer) Option
- func WithStoragePathStyle(hasher imagorpath.StorageHasher) Option
- func WithStorages(savers ...Storage) Option
- func WithUnsafe(unsafe bool) Option
- type Processor
- type Stat
- type Stater
- type Storage
- type TemplateData
Constants ¶
const Version = "1.8.5"
Version imagor version
Variables ¶
var ( // ErrNotFound not found error ErrNotFound = NewError("not found", http.StatusNotFound) // ErrInvalid syntactic invalid path error ErrInvalid = NewError("invalid", http.StatusBadRequest) // ErrMethodNotAllowed method not allowed error ErrMethodNotAllowed = NewError("method not allowed", http.StatusMethodNotAllowed) // ErrSourceNotAllowed http source not allowed error ErrSourceNotAllowed = NewError("http source not allowed", http.StatusForbidden) // ErrSignatureMismatch URL signature mismatch error ErrSignatureMismatch = NewError("url signature mismatch", http.StatusForbidden) // ErrTimeout timeout error ErrTimeout = NewError("timeout", http.StatusRequestTimeout) // ErrExpired expire error ErrExpired = NewError("expired", http.StatusGone) // ErrUnsupportedFormat unsupported format error ErrUnsupportedFormat = NewError("unsupported format", http.StatusNotAcceptable) // ErrMaxSizeExceeded maximum size exceeded error ErrMaxSizeExceeded = NewError("maximum size exceeded", http.StatusBadRequest) // ErrMaxResolutionExceeded maximum resolution exceeded error ErrMaxResolutionExceeded = NewError("maximum resolution exceeded", http.StatusUnprocessableEntity) // ErrTooManyRequests too many requests error ErrTooManyRequests = NewError("too many requests", http.StatusTooManyRequests) // ErrInternal internal error ErrInternal = NewError("internal error", http.StatusInternalServerError) )
Functions ¶
This section is empty.
Types ¶
type Blob ¶ added in v0.6.0
Blob imagor data blob abstraction
func NewBlob ¶ added in v0.9.0
func NewBlob(newReader func() (reader io.ReadCloser, size int64, err error)) *Blob
NewBlob creates imagor Blob from io.ReadCloser and size
func NewBlobFromBytes ¶ added in v0.9.0
NewBlobFromBytes creates imagor Blob from []byte buffer
func NewBlobFromFile ¶ added in v1.0.0
NewBlobFromFile creates imagor Blob from file path and optional file info checks
func NewBlobFromJsonMarshal ¶ added in v1.0.0
NewBlobFromJsonMarshal creates imagor Blob from json marshal of any object
func NewBlobFromMemory ¶ added in v1.1.1
NewBlobFromMemory creates imagor Blob from raw RGB/RGBA buffer
func NewEmptyBlob ¶ added in v0.9.0
func NewEmptyBlob() *Blob
NewEmptyBlob creates empty imagor Blob
func (*Blob) ContentType ¶ added in v0.9.0
ContentType returns content type
func (*Blob) FilePath ¶ added in v0.6.0
FilePath returns Blob file path if blob is created from file
func (*Blob) NewReadSeeker ¶ added in v1.1.0
func (b *Blob) NewReadSeeker() (io.ReadSeekCloser, int64, error)
NewReadSeeker create read seeker if reader supports seek, or attempts to simulate seek using memory or temp file buffer
func (*Blob) NewReader ¶ added in v0.9.0
func (b *Blob) NewReader() (reader io.ReadCloser, size int64, err error)
NewReader creates new io.ReadCloser and returns size if known
func (*Blob) Release ¶ added in v1.6.0
Release stops reading from the source early and releases resources. This is safe to call multiple times and from multiple goroutines. Only works for blobs that use fanoutreader (when fanout is enabled).
func (*Blob) SetContentType ¶ added in v1.0.0
SetContentType set Blob content type. which overrides default sniffing if this is set
func (*Blob) SupportsAnimation ¶ added in v0.8.0
SupportsAnimation check if blob supports animation
type BlobType ¶ added in v0.8.19
type BlobType int
BlobType blob content type
const ( BlobTypeUnknown BlobType = iota BlobTypeEmpty BlobTypeMemory BlobTypeJSON BlobTypeJPEG BlobTypePNG BlobTypeGIF BlobTypeWEBP BlobTypeJXL BlobTypeAVIF BlobTypeHEIF BlobTypeTIFF BlobTypeJP2 BlobTypeBMP BlobTypePDF BlobTypeSVG BlobTypeRAF BlobTypeORF BlobTypeRW2 BlobTypeX3F BlobTypeCR3 BlobTypeCR2 )
BlobType enum
type Cacher ¶ added in v1.7.3
Cacher is an optional Processor interface for in-memory blob caching. LoadFromCache is called by imagor.Do() before loadStorage; on a hit the cached blob is passed directly to Process(), skipping loader/storage I/O entirely.
w and h are the requested output dimensions used to determine cache eligibility, not to select a blob of that size. Return (nil, false) when w or h is zero (unknown size) or exceeds the cache budget — the cache holds a single downscaled copy per image path and cannot safely serve those requests.
type Detector ¶ added in v1.8.0
type Detector interface {
Startup(ctx context.Context) error
Detect(ctx context.Context, imagePath string, blob *Blob) ([]DetectorRegion, error)
Shutdown(ctx context.Context) error
}
Detector detects regions of interest in a raw pixel buffer. Implementations are free to perform any kind of detection (faces, objects, text boxes, etc.) — the only contract is the coordinate space.
imagePath identifies the source image (e.g. URL path) and is used as a cache key by implementations that cache results. Pass an empty string to opt out of caching for a particular call.
blob must be a BlobTypeMemory blob created with NewBlobFromMemory, carrying row-major sRGB/sRGBA pixels. Retrieve dimensions via blob.Memory().
Returned regions must use normalised coordinates in [0.0, 1.0] relative to the image width / height stored in blob.
type DetectorAdder ¶ added in v1.8.0
type DetectorAdder interface {
AddDetector(Detector)
}
DetectorAdder is implemented by processors that accept one or more Detectors. imagorface and other detector plugins use this interface to wire a detector into a processor without importing the processor package directly.
type DetectorRegion ¶ added in v1.8.0
type DetectorRegion struct {
Left, Top, Right, Bottom float64
Score float64 // detection confidence; 0 means not provided
Name string // class name e.g. "face"; empty means not provided
}
DetectorRegion is a normalised bounding box where all fields are ratios in [0.0, 1.0] relative to the image dimensions passed to Detector.Detect.
type ErrForward ¶ added in v1.1.0
type ErrForward struct {
imagorpath.Params
}
ErrForward indicator passing imagorpath.Params to next processor
type Error ¶
Error imagor error convention
func NewErrorFromStatusCode ¶
NewErrorFromStatusCode creates imagor Error solely from status code
type Imagor ¶
type Imagor struct {
Unsafe bool
Signer imagorpath.Signer
GetSigner func(*http.Request) imagorpath.Signer
GetResultKey func(*http.Request, imagorpath.Params) string
StoragePathStyle imagorpath.StorageHasher
ResultStoragePathStyle imagorpath.ResultStorageHasher
BasePathRedirect string
Loaders []Loader
Storages []Storage
ResultStorages []Storage
Processors []Processor
RequestTimeout time.Duration
LoadTimeout time.Duration
SaveTimeout time.Duration
ProcessTimeout time.Duration
CacheHeaderTTL time.Duration
CacheHeaderSWR time.Duration
ProcessConcurrency int64
ProcessQueueSize int64
AutoWebP bool
AutoAVIF bool
AutoJPEG bool
ModifiedTimeCheck bool
DisableErrorBody bool
DisableParamsEndpoint bool
EnablePostRequests bool
ResponseRawOnError bool
BaseParams string
Logger *zap.Logger
Debug bool
// contains filtered or unexported fields
}
Imagor main application
func (*Imagor) ServeBlob ¶ added in v1.3.1
func (app *Imagor) ServeBlob( ctx context.Context, blob *Blob, p imagorpath.Params, ) (*Blob, error)
ServeBlob serves imagor Blob with context and params, skipping loader and storages
func (*Imagor) ServeHTTP ¶
func (app *Imagor) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler for imagor operations
type Option ¶
type Option func(app *Imagor)
Option imagor option
func WithAutoAVIF ¶ added in v0.8.19
WithAutoAVIF experimental with auto AVIF option based on browser Accept header
func WithAutoJPEG ¶ added in v1.5.16
WithAutoJPEG with auto JPEG option when JPEG or no specific format is requested
func WithAutoWebP ¶ added in v0.8.16
WithAutoWebP with auto WebP option based on browser Accept header
func WithBaseParams ¶ added in v0.9.0
WithBaseParams with base params string option
func WithBasePathRedirect ¶ added in v0.8.16
WithBasePathRedirect with base path redirect option
func WithCacheHeaderNoCache ¶ added in v0.8.26
WithCacheHeaderNoCache with browser cache header no-cache option
func WithCacheHeaderSWR ¶ added in v0.8.26
WithCacheHeaderSWR with browser cache header swr option
func WithCacheHeaderTTL ¶ added in v0.1.5
WithCacheHeaderTTL with browser cache header ttl option
func WithDetector ¶ added in v1.8.0
WithDetector wires d into every DetectorAdder processor in the app. Passing nil is a no-op, allowing callers to unconditionally call WithDetector and skip wiring when the feature is disabled.
func WithDetectors ¶ added in v1.8.0
WithDetectors wires multiple detectors into every DetectorAdder processor in the app. Like WithDetector, nil entries are skipped.
func WithDisableErrorBody ¶ added in v0.9.0
WithDisableErrorBody with disable error body option, resulting empty response on error
func WithDisableParamsEndpoint ¶ added in v0.9.0
WithDisableParamsEndpoint with disable imagor /params endpoint
func WithEnablePostRequests ¶ added in v1.6.0
WithEnablePostRequests with enable POST requests option
func WithGetResultKey ¶ added in v1.8.5
func WithGetSigner ¶ added in v1.8.5
func WithGetSigner(fn func(*http.Request) imagorpath.Signer) Option
func WithLoadTimeout ¶ added in v0.1.5
WithLoadTimeout with load timeout option for loader and storage
func WithModifiedTimeCheck ¶ added in v0.8.23
WithModifiedTimeCheck with option for modified time check of storage against result storage
func WithOptions ¶ added in v1.2.3
WithOptions with nested options
func WithProcessConcurrency ¶ added in v0.8.7
WithProcessConcurrency maximum number of processor call to be executed simultaneously.
func WithProcessQueueSize ¶ added in v0.9.13
WithProcessQueueSize maximum number of processor call that can be put to a queue
func WithProcessTimeout ¶ added in v0.5.4
WithProcessTimeout with process timeout option for processor
func WithProcessors ¶
WithProcessors with processor option
func WithRequestTimeout ¶
WithRequestTimeout with request timeout option
func WithResponseRawOnError ¶ added in v1.6.16
WithResponseRawOnError with response raw on error option
func WithResultStoragePathStyle ¶ added in v1.1.0
func WithResultStoragePathStyle(hasher imagorpath.ResultStorageHasher) Option
WithResultStoragePathStyle with result storage path style hasher option
func WithResultStorages ¶ added in v0.5.5
WithResultStorages with result storages option
func WithSaveTimeout ¶
WithSaveTimeout with save timeout option for storage
func WithSigner ¶ added in v0.8.23
func WithSigner(signer imagorpath.Signer) Option
WithSigner with URL signature signer option
func WithStoragePathStyle ¶ added in v1.1.0
func WithStoragePathStyle(hasher imagorpath.StorageHasher) Option
WithStoragePathStyle with storage path style hasher option
type Processor ¶
type Processor interface {
// Startup processor startup lifecycle,
// called only once for the application lifetime
Startup(ctx context.Context) error
// Process Blob with given params and loader function
Process(ctx context.Context, blob *Blob, params imagorpath.Params, load LoadFunc) (*Blob, error)
// Shutdown processor shutdown lifecycle,
// called only once for the application lifetime
Shutdown(ctx context.Context) error
}
Processor process image buffer
type Storage ¶
type Storage interface {
// Get data Blob by key
Get(r *http.Request, key string) (*Blob, error)
// Stat get Blob Stat by key
Stat(ctx context.Context, key string) (*Stat, error)
// Put data Blob by key
Put(ctx context.Context, key string, blob *Blob) error
// Delete delete data Blob by key
Delete(ctx context.Context, key string) error
}
Storage image storage interface
type TemplateData ¶ added in v1.6.0
TemplateData holds data for template rendering
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
imagor
command
|
|
|
examples
|
|
|
from_buffer
command
|
|
|
from_file
command
|
|
|
from_go_image
command
|
|
|
io_reader_writer
command
|
|
|
server
command
|
|
|
loader
|
|
|
metrics
|
|
|
processor
|
|
|
storage
|
|

