Documentation ¶
Overview ¶
Package media is for determining information about media without decoding the entire file.
Example Usage:
giphy := "https://media1.giphy.com/media/l0ErxFClZX9L3bgBi/giphy.gif" r, err := http.Get(giphy) if err != nil { log.Fatal(err) } defer r.Body.Close() m, err := media.Parse(r.Body) if err != nil { log.Fatal(err) } fmt.Printf("media dimensions: %v\n", m.Size()) // media dimensions: {480 270} fmt.Printf("content type: %q\n", m.Type()) // content type: "image/gif"
MIT License Copyright (c) 2020 Montana Flynn (https://montanaflynn.com)
Index ¶
Constants ¶
View Source
const ( // PNGType media type PNGType ContentType = "image/png" // GIFType media type GIFType = "image/gif" // BMPType media type BMPType = "image/bmp" // JPEGType media type JPEGType = "image/jpeg" )
Variables ¶
View Source
var ( // ErrUnknownContentType is when media is an unknown type ErrUnknownContentType = errors.New("media: unknown media type") // ErrUnsupportedSize is when media type doesn't implement size ErrUnsupportedSize = errors.New("media: unsupported size") // ErrPNGMissingIHDR is when a png is missing the HDR header ErrPNGMissingIHDR = errors.New("media: invalid png missing IHDR") // ErrBMPInvalidHeaderLength is when a bmp has invalid header length ErrBMPInvalidHeaderLength = errors.New("media: invalid bmp header length") )
Functions ¶
This section is empty.
Types ¶
type BMP ¶
type BMP struct { ContentType ContentType Dimensions Dimensions Format BMPFormat }
BMP holds the BMP
type BMPFormat ¶
type BMPFormat string
BMPFormat is the type of the media
const ( // OS2Format bmp format OS2Format BMPFormat = "OS/2" // WindowsFormat bmp format WindowsFormat = "Windows" )
type ContentType ¶
type ContentType string
ContentType is the type of the media
func DetectContentType ¶
func DetectContentType(r io.Reader) (ContentType, []byte, error)
DetectContentType returns the ContentType from the first 32 bytes
type Media ¶
type Media interface { Size() Dimensions Type() ContentType }
Media is an interface for getting information from media
Click to show internal directories.
Click to hide internal directories.