size

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package size is for determining dimensions of media without decoding the entire file.

Example Usage:

giphy := "https://media1.giphy.com/media/l0ErxFClZX9L3bgBi/giphy.gif"
res, err := http.Get(giphy)
if err != nil {
	log.Fatal(err)
}
defer res.Body.Close()
size, err := size.Parse(res.Body)
if err != nil {
	log.Fatal(err)
}
jsonBytes, err := json.Marshal(size)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%s", jsonBytes)
// {"Width":480,"Height":270,"MediaType":"GIF"}

MIT License Copyright (c) 2020 Montana Flynn (https://montanaflynn.com)

Index

Constants

View Source
const (
	// PNG media type
	PNG MediaType = "PNG"

	// GIF media type
	GIF = "GIF"

	// BMP media type
	BMP = "BMP"

	// JPEG media type
	JPEG = "JPEG"
)

Variables

View Source
var (
	// ErrUnknownMediaType is when media is an unknown type
	ErrUnknownMediaType = fmt.Errorf("Unknown media type")

	// ErrUnsupportedSize is when media type doesn't implement size
	ErrUnsupportedSize = fmt.Errorf("Unsupported size")

	// ErrPNGMissingIHDR is when a png is missing the HDR header
	ErrPNGMissingIHDR = fmt.Errorf("Invalid png missing IHDR")

	// ErrBMPInvalidHeaderLength is when a bmp has invalid header length
	ErrBMPInvalidHeaderLength = fmt.Errorf("Invalid bmp header length")
)

Functions

This section is empty.

Types

type MediaType added in v0.0.4

type MediaType string

MediaType is the type of the media

func DetectMediaType added in v0.0.4

func DetectMediaType(r io.Reader) (MediaType, []byte, error)

DetectMediaType returns the MediaType from the first 32 bytes

type Size

type Size struct {
	Width     int
	Height    int
	MediaType MediaType
}

Size holds the media dimensions

func Parse

func Parse(r io.Reader) (Size, error)

Parse returns the media information including file type and dimensions

Jump to

Keyboard shortcuts

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