images

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrImageFormatNotFound = fmt.Errorf("Image format not found")

ErrImageFormatNotFound is used when the provided image format is unsupported

View Source
var ErrInvalidFileType = errors.New("Invalid image type. Supported image formats are JPG and PNG")

ErrInvalidFileType is an error when the user uploads a bad file type

Functions

This section is empty.

Types

type CropAnchorMode

type CropAnchorMode string

CropAnchorMode is used to describe from where a crop happens

var CropAnchorModeCentered CropAnchorMode = "centered"

CropAnchorModeCentered crops from the center

var CropAnchorModeTopLeft CropAnchorMode = "top-left"

CropAnchorModeTopLeft crops from top-left

type CropOptions

type CropOptions struct {
	Anchor     image.Point
	AnchorMode CropAnchorMode
	Height     int
	UseRatio   bool
	Width      int
}

CropOptions describes how an image is cropped. Width/Height defines how big to make the image. AnchorMode describes how to apply the crop anchor point. Valid options are top-left, centered. Anchor describes the X/Y offset from top left if the anchor mode is top-left. UseRatio, when true, makes width/height a ratio-based instead of pixels.

func NewCropOptions

func NewCropOptions() *CropOptions

NewCropOptions creates a new structure with default values filled in

type IImageCropper

type IImageCropper interface {
	Crop(imageBytes []byte, cropOptions *CropOptions) (*bytes.Buffer, error)
}

IImageCropper is an interface for cropping images

type IResizer

type IResizer interface {
	ResizeImage(source io.ReadSeeker, contentType string, imageSize ImageSize) (*bytes.Buffer, error)
}

IResizer is an interface to describe structs that resize images

type ImageCropper

type ImageCropper struct{}

ImageCropper crops images

func (*ImageCropper) Crop

func (ic *ImageCropper) Crop(imageBytes []byte, cropOptions *CropOptions) (*bytes.Buffer, error)

Crop takes an image reader and performs a crop based on the options provided. It returns the newly cropped image in the form of a PNG

type ImageSize

type ImageSize string

ImageSize describes generic image sizes

const (
	DEFAULT   ImageSize = "default"
	THUMBNAIL ImageSize = "thumbnail"
	SMALL     ImageSize = "small"
	MEDIUM    ImageSize = "medium"
	LARGE     ImageSize = "large"
)

func (ImageSize) String

func (is ImageSize) String() string

type MockResizer

type MockResizer struct {
	ResizeImageFunc func(source io.ReadSeeker, contentType string, imageSize ImageSize) (*bytes.Buffer, error)
}

func (*MockResizer) ResizeImage

func (m *MockResizer) ResizeImage(source io.ReadSeeker, contentType string, imageSize ImageSize) (*bytes.Buffer, error)

type Resizer

type Resizer struct{}

A Resizer contains methods for resizing images and re-encoding them.

func (*Resizer) ResizeImage

func (r *Resizer) ResizeImage(source io.ReadSeeker, contentType string, imageSize ImageSize) (*bytes.Buffer, error)

ResizeImage takes a source image, content type (MIME), and a image size ( THUMBNAIL, SMALL, MEDIUM, LARGE) and resizes proportionally.

Jump to

Keyboard shortcuts

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