geometry

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flags

type Flags struct {
	WidthPercent   bool
	HeightPercent  bool
	OffsetXPercent bool
	OffsetYPercent bool
	Force          bool
	OnlyGrow       bool
	OnlyShrink     bool
	Fill           bool
}

type Geometry

type Geometry struct {
	Width  float64
	Height float64
	X      int
	Y      int
	Flags  Flags
}

func ParseGeometry

func ParseGeometry(geometry string) (Geometry, error)

ParseGeometry parse a geometry string in the form of "WIDTHxHEIGHT{+}X{+}Y{!<>}"

WIDTH and HEIGHT are integers, and can be followed by '%' to indicate percentage.

One WIDTH or HEIGHT is required.

X and Y are offsets, and must be preceded by '+'.

The '!' flag forces the image to be resized to the specified dimensions.

The '<' flag only allows the image to be resized if it is smaller than the specified dimensions.

The '>' flag only allows the image to be resized if it is larger than the specified dimensions.

The '^' flag forces the image to fill the smallest dimension of the specified dimensions.

Examples:

"100x200" - width 100, height 200 "50%x50%" - width 50%, height 50% "300x" - width 300 "x400" - height 400 "100x200+50+50%" - width 100, height 200, x offset 50, y offset 50% "+50+50" - x offset 50, y offset 50, width and height are 100% of the http of the image "100x100%+50+50" - width 100, height 100%, x offset 50, y offset 50

func (Geometry) ApplyMeta

func (g Geometry) ApplyMeta(image *vips.ImageRef) Geometry

ApplyMeta returns a geometry that is modified as determined by the meta characters: %, !, <, >, ^ in relation to the provided image.

Final image dimensions are adjusted so as to preserve the aspect ratio as much as possible, while generating a integer (pixel) size, and fitting the image within the specified geometry width and height.

Flags are interpreted...

%   geometry size is given percentage of original width and height given
!   do not try to preserve aspect ratio
<   only enlarge images smaller that geometry
>   only shrink images larger than geometry
^   fill given area

A description of each parameter follows:

o geometry:  The geometry string (e.g. "100x100+10+10").
o x,y:  The x and y offset, set according to the geometry specification.
o width,height:  The width and height of original image, modified by
  the given geometry specification.

func (Geometry) String

func (g Geometry) String() string

Jump to

Keyboard shortcuts

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