image

package
v0.0.0-...-cf015e3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 16 Imported by: 7

Documentation

Index

Constants

View Source
const (
	MimetypeDetectorTypeFastimage = "fastimage"
	MimetypeDetectorTypeSniff     = "sniff"
)

Variables

View Source
var (
	Extensions = map[string]string{
		"image/bmp":  "bmp",
		"image/gif":  "gif",
		"image/jpeg": "jpg",
		"image/png":  "png",
		"image/webp": "webp",
	}

	HeaderKeys = []string{
		"Age",
		"Content-Type",
		"Date",
		"Etag",
		"Last-Modified",
	}
)

Functions

func MimetypeDetectorExtension

func MimetypeDetectorExtension(uri *url.URL) (string, error)

Detect mimetype by looking at the URL extension

func MimetypeDetectorFastimage

func MimetypeDetectorFastimage(uri *url.URL) (string, error)

Detect mimetype with third-party fastimage library. Overhead warning: fastimage makes a request (albeit a very small partial one) upon each detection.

func MimetypeDetectorSniff

func MimetypeDetectorSniff(uri *url.URL) (string, error)

Detect mimetype using go native content detection which implements the MIME Sniffing alorithm described here: https://mimesniff.spec.whatwg.org/

Types

type ImageFile

type ImageFile struct {
	Filepath  string
	Headers   map[string]string
	Key       string
	Processed []byte
	Source    []byte
	Storage   *storage.Storage
}

func FromStorage

func FromStorage(ctx context.Context, storage *storagepkg.Storage, filepath string) (*ImageFile, error)

FromStorage retrieves an ImageFile from storage

func FromURL

func FromURL(ctx context.Context, u *url.URL, userAgent string) (*ImageFile, error)

FromURL retrieves an ImageFile from an url

func (*ImageFile) Content

func (i *ImageFile) Content() []byte

func (*ImageFile) ContentType

func (i *ImageFile) ContentType() string

func (*ImageFile) Filename

func (i *ImageFile) Filename() string

func (*ImageFile) FilenameExt

func (i *ImageFile) FilenameExt() string

func (*ImageFile) Format

func (i *ImageFile) Format() string

func (*ImageFile) Path

func (i *ImageFile) Path() string

Path joins the given file to the storage path

func (*ImageFile) Save

func (i *ImageFile) Save(ctx context.Context) error

func (*ImageFile) URL

func (i *ImageFile) URL() string

type MimetypeDetectorFunc

type MimetypeDetectorFunc func(*url.URL) (string, error)

func GetMimetypeDetector

func GetMimetypeDetector(mimetypeDetectorType string) MimetypeDetectorFunc

Jump to

Keyboard shortcuts

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