Documentation
¶
Overview ¶
Package aspeq matches and converts images to "standard" aspect ratios
Index ¶
Examples ¶
Constants ¶
const Version = "0.6.0"
Variables ¶
var Academy = &AspectRatio{1.375, "academy", 11, 8, Landscape}
var Cinemascope = &AspectRatio{2.35, "cinemascope", 47, 20, Landscape}
var Cinerama = &AspectRatio{2.59, "cinerama", 70, 27, Landscape}
var CircleVision = &AspectRatio{12.0, "circle-vision", 12, 1, Landscape}
var Classic = &AspectRatio{0.6667, "classic", 2, 3, Portrait}
var Flat = &AspectRatio{1.85, "flat", 37, 20, Landscape}
var FourThirds = &AspectRatio{1.333, "four-thirds", 4, 3, Landscape}
var Insta = &AspectRatio{0.5625, "insta", 9, 16, Portrait}
var Instax = &AspectRatio{0.75, "instax", 3, 4, Portrait}
var Leica = &AspectRatio{1.50, "leica", 3, 2, Landscape}
var Movietone = &AspectRatio{1.19, "movietone", 19, 16, Landscape}
var Polyvision = &AspectRatio{4.0, "polyvision", 4, 1, Landscape}
var Ratios = []*AspectRatio{ Insta, Classic, Instax, Square, Movietone, FourThirds, Academy, Leica, Super16, SixteenNine, Flat, Univisium, Cinemascope, Cinerama, Widelux, Polyvision, CircleVision, }
All named aspect ratios
var SixteenNine = &AspectRatio{1.77, "sixteen-nine", 16, 9, Landscape}
var Square = &AspectRatio{1.0, "square", 1, 1, Balanced}
var Super16 = &AspectRatio{1.66, "super16", 5, 3, Landscape}
var Univisium = &AspectRatio{2.0, "univisium", 2, 1, Landscape}
var Widelux = &AspectRatio{3.0, "widelux", 3, 1, Landscape}
Functions ¶
func CropImage ¶ added in v0.3.9
func CropImage(img image.Image, ar *AspectRatio) image.Image
CropImage crops an image (img) to the desired aspect ratio (ar)
func CropPath ¶ added in v0.3.9
func CropPath(path string, ar *AspectRatio) (image.Image, error)
CropImage crops a file (path) to the desired aspect ratio (ar)
Example ¶
package main
import (
"blekksprut.net/aspeq"
"fmt"
)
func main() {
img, err := aspeq.CropPath("1.66.jpeg", aspeq.Square)
if err != nil {
panic(err)
}
bounds := img.Bounds()
fmt.Printf("%dx%d\n", bounds.Dx(), bounds.Dy())
}
Output: 24x24
Example (Cinerama) ¶
package main
import (
"blekksprut.net/aspeq"
"fmt"
)
func main() {
img, err := aspeq.CropPath("1.66.jpeg", aspeq.Cinerama)
if err != nil {
panic(err)
}
bounds := img.Bounds()
fmt.Printf("%dx%d\n", bounds.Dx(), bounds.Dy())
}
Output: 40x15
Example (Classic) ¶
package main
import (
"blekksprut.net/aspeq"
"fmt"
)
func main() {
img, err := aspeq.CropPath("1.66.jpeg", aspeq.Classic)
if err != nil {
panic(err)
}
bounds := img.Bounds()
fmt.Printf("%dx%d\n", bounds.Dx(), bounds.Dy())
}
Output: 16x24
Types ¶
type AspectRatio ¶
type AspectRatio struct {
Ratio float64
Name string
X int64
Y int64
Orientation Orientation
}
Represents a "standard", or named aspect ratio
func FromImage ¶
func FromImage(img image.Image) *AspectRatio
FromImage returns the closest named aspect ratio for the given image
func FromPath ¶ added in v0.3.9
func FromPath(path string) (*AspectRatio, error)
FromReader reads image data from the file at path, decodes it, and returns the closest matching named aspect ratio.
Example ¶
package main
import (
"blekksprut.net/aspeq"
"fmt"
)
func main() {
ar, err := aspeq.FromPath("1.66.jpeg")
if err != nil {
panic(err)
}
fmt.Println(ar.Name)
}
Output: super16
func FromReader ¶ added in v0.5.1
func FromReader(rd io.Reader) (*AspectRatio, error)
FromReader reads image data from the provided io.Reader, decodes it, and returns the closest matching named aspect ratio.
func Match ¶ added in v0.2.0
func Match(w int, h int) *AspectRatio
Match returns the closest named aspect ratio for the given dimensions
Example ¶
package main
import (
"blekksprut.net/aspeq"
"fmt"
)
func main() {
ar := aspeq.Match(1920, 1080)
fmt.Println(ar.Name)
}
Output: sixteen-nine
func (*AspectRatio) Xy ¶
func (ar *AspectRatio) Xy() string
Xy returns the aspect ratio as <width>:<height>
type Orientation ¶
type Orientation int
Represents an image orientation - Balanced (1:1), Portrait or Landscape
const ( Balanced Orientation = iota + 1 Portrait Landscape )