mimage

package
v0.0.0-...-94ee829 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MagickBin string

MagickBin is the location of the `magick` binary that ships with the ImageMagick project (an image manipulation utility).

Must be configured to use this package.

View Source
var MozJPEGBin string

MozJPEGBin is the location of the `cjpeg` binary that ships with the mozjpeg project (a JPG optimizer). If configured, JPEGs are passed through an optimization pass after resizing them.

View Source
var PNGQuantBin string

PNGQuantBin is the location of the `pnqquant` binary (a PNG optimizer). If configured, PNGs are passed through an optimization pass after resizing them.

View Source
var TempDir string

TempDir is a path to a temporary directory where fetched images can be stored.

Functions

func FetchAndResizeImage

func FetchAndResizeImage(c *modulir.Context,
	u *url.URL, targetDir, targetSlug, targetExt string,
	cropGravity PhotoGravity, photoSizes []PhotoSize,
) (bool, error)

FetchAndResizeImage fetches an image from a URL and resizes it according to specifications.

func ResizeImage

func ResizeImage(c *modulir.Context,
	originalPath, targetDir, targetSlug, targetExt string,
	cropGravity PhotoGravity, photoSizes []PhotoSize,
) (bool, error)

ResizeImage fetches an image from a URL and resizes it according to specifications.

Types

type PhotoCropSettings

type PhotoCropSettings struct {
	// Square defines the crop ratio that will be used if the photo is square.
	//
	// Should be a string like "3:2", or empty for no crop.
	Square string

	// Landscape defines the crop ratio that will be used if the photo's width
	// is greater than its height.
	//
	// Should be a string like "3:2", or empty for no crop.
	Landscape string

	// Portrait defines the crop ratio that will be used if the photo's height
	// is greater than its width.
	//
	// Should be a string like "3:2", or empty for no crop.
	Portrait string
}

PhotoCropSettings are directives on how the image should be cropped depending on its proportions.

type PhotoGravity

type PhotoGravity string

PhotoGravity is the crop gravity for ImageMagick.

const (
	PhotoGravityCenter    PhotoGravity = "center"
	PhotoGravityEast      PhotoGravity = "east"
	PhotoGravityNorth     PhotoGravity = "north"
	PhotoGravityNorthEast PhotoGravity = "northeast"
	PhotoGravityNorthWest PhotoGravity = "northwest"
	PhotoGravitySouth     PhotoGravity = "south"
	PhotoGravitySouthEast PhotoGravity = "southeast"
	PhotoGravitySouthWest PhotoGravity = "southwest"
	PhotoGravityWest      PhotoGravity = "west"
)

Possible options for photo crop gravity.

type PhotoSize

type PhotoSize struct {
	Suffix       string
	Width        int
	CropSettings *PhotoCropSettings
}

PhotoSize are the specifications for a target photo crop and resize.

Jump to

Keyboard shortcuts

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