aspeq

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: BSD-2-Clause Imports: 13 Imported by: 1

README

aspeq

aspeq finds the closest "standard" aspect ratio from an image file, or from relative or absolute dimensions (width and height)

defined ratios

  • insta (9:16)
  • classic (2:3)
  • instax (3:4)
  • square (1:1)
  • movietone (1.19:1)
  • four-thirds (4:3)
  • academy (1.375:1)
  • leica (3:2)
  • super16 (5:3)
  • sixteen-nine (16:9)
  • flat (1.85:1)
  • univisium (2:1)
  • cinemascope (2.35:1)
  • cinerama (2.59:1)
  • widelux (3:1)
  • polyvision (4:1)
  • circle-vision (12:1)

command line

$ aspeq *.jpeg
1.66.jpeg: super16
1.77.jpeg: sixteen-nine
2.35.jpeg: cinemascope

$ aspeq -x 1.66.jpeg
1.66.jpeg: 5:3

$ aspeq -o 1.66.jpeg
1.66.jpeg: landscape

slasher lets you crop images to a specific aspect ratio

$ slasher -o leica.jpg -a leica super16.jpg
$ slasher -o closest.jpg weird.jpg # crop to closest aspect ratio
$ slasher -a cinerama cat.jpg # prints cinerama dimensions
1600x617
$ slasher -l # lists available aspect ratios

go

package main

import (
  "fmt"
  "blekksprut.net/aspeq"
)

func main() {
  ratio := aspeq.Match(320, 240)
  fmt.Println(ratio.Xy()) // prints "4:3"

  ar, err := aspeq.FromPath("1.66.jpeg") // a 40:24 image
  if err != nil {
    panic(err)
  }
  fmt.Println(ar.Name) // prints "super16"
}

Documentation

Overview

Package aspeq matches and converts images to "standard" aspect ratios

Index

Examples

Constants

View Source
const Version = "0.6.0"

Variables

View Source
var Academy = &AspectRatio{1.375, "academy", 11, 8, Landscape}
View Source
var Cinemascope = &AspectRatio{2.35, "cinemascope", 47, 20, Landscape}
View Source
var Cinerama = &AspectRatio{2.59, "cinerama", 70, 27, Landscape}
View Source
var CircleVision = &AspectRatio{12.0, "circle-vision", 12, 1, Landscape}
View Source
var Classic = &AspectRatio{0.6667, "classic", 2, 3, Portrait}
View Source
var Flat = &AspectRatio{1.85, "flat", 37, 20, Landscape}
View Source
var FourThirds = &AspectRatio{1.333, "four-thirds", 4, 3, Landscape}
View Source
var Insta = &AspectRatio{0.5625, "insta", 9, 16, Portrait}
View Source
var Instax = &AspectRatio{0.75, "instax", 3, 4, Portrait}
View Source
var Leica = &AspectRatio{1.50, "leica", 3, 2, Landscape}
View Source
var Movietone = &AspectRatio{1.19, "movietone", 19, 16, Landscape}
View Source
var Polyvision = &AspectRatio{4.0, "polyvision", 4, 1, Landscape}

All named aspect ratios

View Source
var SixteenNine = &AspectRatio{1.77, "sixteen-nine", 16, 9, Landscape}
View Source
var Square = &AspectRatio{1.0, "square", 1, 1, Balanced}
View Source
var Super16 = &AspectRatio{1.66, "super16", 5, 3, Landscape}
View Source
var Univisium = &AspectRatio{2.0, "univisium", 2, 1, Landscape}
View Source
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

func Register added in v0.6.0

func Register(name string, x, y int64)

Register adds a custom aspect ratio

func Unregister added in v0.6.0

func Unregister(name string)

Unregister removes an existing ratio

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
)

Directories

Path Synopsis
cmd
aspeq command
slasher command

Jump to

Keyboard shortcuts

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