imagemanipulator

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package imagemanipulator resizes, crops, rotates and flips pictures, and encodes them again. It's plain Go, so it needs no plugin add, and runs the same on phones, on the web and on your server.

img, err := imagemanipulator.Decode(photo.Data)
img = imagemanipulator.Fit(img, 1200)
img = imagemanipulator.Rotate(img, 90)
jpeg, err := imagemanipulator.JPEG(img, 85)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Crop

func Crop(img image.Image, x, y, w, h int) image.Image

Crop cuts out part of it. Whatever falls outside the picture is left off.

func Decode

func Decode(b []byte) (image.Image, error)

Decode reads a JPEG, PNG or GIF. A GIF gives its first frame. It doesn't apply the orientation a camera writes into a JPEG, so a photo straight from a camera may need a Rotate.

func Fit

func Fit(img image.Image, max int) image.Image

Fit shrinks it so that neither side is over max, keeping its shape. A picture that's already small enough comes back as it is.

func Flip

func Flip(img image.Image, vertical bool) image.Image

Flip mirrors it.

func JPEG

func JPEG(img image.Image, quality int) ([]byte, error)

JPEG encodes it. JPEG has no transparency: clear parts come out black.

func PNG

func PNG(img image.Image) ([]byte, error)

PNG encodes it, keeping transparency.

func Resize

func Resize(img image.Image, w, h int) image.Image

Resize scales it to exactly w by h, averaging pixels on the way down and blending them on the way up.

func Rotate

func Rotate(img image.Image, degrees int) image.Image

Rotate turns it clockwise. Other angles than 90, 180 and 270 change nothing.

Types

This section is empty.

Jump to

Keyboard shortcuts

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