imageflow

package module
v0.0.0-...-ea10365 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: AGPL-3.0 Imports: 6 Imported by: 0

README

Go Binding for Imageflow

WindowsMacosLinux

Quickly scale or modify images and optimize them for the web.

If the AGPLv3 does not work for you, you can get a commercial license on a sliding scale. If you have more than 1 server doing image processing your savings should cover the cost.

Docs are here

Installation

Imageflow dependents on libimageflow for image processing capabilities. libimageflow is available as the static and dynamic shared library on Linux and macOS. Currently libimageflow is available as a dynamic library for Windows. Prebuilt shared libraries are available here. Add libimageflowto OS path. Then it can be downloaded usinggo get.

$ go get github.com/imazen/imageflow-go

Usage

A simple go program to create two image of different size.

package main;

import (
	"io/ioutil"

	imageflow "github.com/imazen/imageflow-go"
)

func main(){
	step:=imageflow.NewStep()
	data,_:=step
	.Decode(imageflow.NewURL("https://jpeg.org/images/jpeg2000-home.jpg"))
	.Branch(func(step *imageflow.Steps){
		step
		.ConstrainWithin(200,200)
		.Encode(imageflow.NewFile("test_1.jpg"),imageflow.MozJPEG{})
	}).ConstrainWithin(400,400)
	.Encode(imageflow.GetBuffer("test"),imageflow.MozJPEG{})
	.Execute()
	ioutil.WriteFile("test_2.jpeg",data["test"],0644)
}

Documentation

Overview

Package imageflow is a fast image processing library

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Black

type Black struct{}

Black is the Implementation of interface Color and used as color black

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer is io operation related to []byte

func GetBuffer

func GetBuffer(key string) *Buffer

GetBuffer is used to get key

func NewBuffer

func NewBuffer(buffer []byte) *Buffer

NewBuffer create a buffer operation

type Color

type Color interface {
	// contains filtered or unexported methods
}

Color must be implemented by all the Colors that can be used by imageflow

type Constrain

type Constrain struct {
	Mode        string         `json:"mode"`
	W           float64        `json:"w"`
	H           float64        `json:"h"`
	Hint        ConstraintHint `json:"hints"`
	Gravity     interface{}    `json:"gravity"`
	CanvasColor interface{}    `json:"canvas_color"`
}

Constrain is used to specify constraints for the image W The width constraint in pixels H The height constraint in pixels Mode A constraint mode Gravity determines how the image is anchored when cropped or padded. {x: 0, y: 0} represents top-left, {x: 50, y: 50} represents center, {x:100, y:100} represents bottom-right. Default: center Hints See resampling hints Canvas_color See Color. The color of padding added to the image.

type ConstraintGravity

type ConstraintGravity struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

ConstraintGravity anchors the image

type ConstraintHint

type ConstraintHint struct {
	SharpenPercent    interface{} `json:"sharpen_percent"`
	DownFilter        interface{} `json:"down_filter"`
	UpFilter          interface{} `json:"up_filter"`
	ScalingColorspace interface{} `json:"scaling_colorspace"`
	BackgroundColor   interface{} `json:"background_color"`
	ResampleWhen      interface{} `json:"resample_when"`
	SharpenWhen       interface{} `json:"sharpen_when"`
}

ConstraintHint is used to provided changes when resampling SharpenPercent (0..100) The amount of sharpening to apply during resampling UpFilter The resampling filter to use if upscaling in one or more directions DownFilter The resampling filter to use if downscaling in both directions. ScalingColorspace Use linear for the best results, or srgb to mimick poorly-written software. srgb can destroy image highlights. BackgroundColor The background color to apply. ResampleWhen One of size_differs, size_differs_or_sharpening_requested, or always. SharpenWhen One of downscaling, upscaling, size_differs, or always Supported Filters robidoux_sharp - A sharper version of the above robidoux_fast - A faster, less accurate version of robidoux ginseng - The default and suggested upsampling filter ginseng_sharp lanczos lanczos_sharp lanczos_2 lanczos_2_sharp cubic cubic_sharp catmull_rom mitchell cubic_b_spline hermite jinc triangle linear box fastest n_cubic n_cubic_sharp

type DrawExact

type DrawExact struct {
	W     float32     `json:"w"`
	H     float32     `json:"h"`
	X     float32     `json:"x"`
	Y     float32     `json:"y"`
	Blend string      `json:"blend"`
	Hints interface{} `json:"hints"`
}

DrawExact is used to copy a part of image

type ExpandCanvas

type ExpandCanvas struct {
	Left   float64     `json:"left"`
	Right  float64     `json:"right"`
	Top    float64     `json:"top"`
	Bottom float64     `json:"bottom"`
	Color  interface{} `json:"color"`
}

ExpandCanvas is used to expand the image

type File

type File struct {
	// contains filtered or unexported fields
}

File is io operation related to file

func NewFile

func NewFile(filename string) *File

NewFile is used to create a file io

type FitBox

type FitBox interface {
	// contains filtered or unexported methods
}

FitBox is used to specify image position

type GIF

type GIF struct{}

GIF is used to encode to gif

type LosslessPNG

type LosslessPNG struct {
	MaxDeflate bool `json:"max_deflate"`
}

LosslessPNG is a encoder for lodepng

type LossyPNG

type LossyPNG struct {
	Quality        int  `json:"quality"`
	MinimumQuality int  `json:"minimum_quality"`
	Speed          int  `json:"speed"`
	MaximumDeflate bool `json:"maximum_deflate"`
}

LossyPNG is used for encoding pngquant

type MarginFitBox

type MarginFitBox struct {
	Left   float64 `json:"left"`
	Right  float64 `json:"right"`
	Top    float64 `json:"top"`
	Bottom float64 `json:"bottom"`
}

MarginFitBox is used to specify image position

type MozJPEG

type MozJPEG struct {
	Quality     uint `json:"quality"`
	Progressive bool `json:"progressive"`
}

MozJPEG is used to encode using mozjpeg library

type PercentageFitBox

type PercentageFitBox struct {
	X1 float64 `json:"x1"`
	Y1 float64 `json:"y1"`
	X2 float64 `json:"x2"`
	Y2 float64 `json:"y2"`
}

PercentageFitBox is used to specify image position

type RectangleToCanvas

type RectangleToCanvas struct {
	FromX float32 `json:"from_x"`
	FromY float32 `json:"from_y"`
	W     float32 `json:"w"`
	H     float32 `json:"h"`
	X     float32 `json:"x"`
	Y     float32 `json:"y"`
}

RectangleToCanvas is used to copy a part of image

type Region

type Region struct {
	X1              float64     `json:"x1"`
	Y1              float64     `json:"y1"`
	X2              float64     `json:"x2"`
	Y2              float64     `json:"y2"`
	BackgroundColor interface{} `json:"background_color"`
}

Region is like a crop command, but you can specify coordinates outside of the image and thereby add padding. It's like a window.

type RegionPercentage

type RegionPercentage struct {
	X1              float64     `json:"x1"`
	Y1              float64     `json:"y1"`
	X2              float64     `json:"x2"`
	Y2              float64     `json:"y2"`
	BackgroundColor interface{} `json:"background_color"`
}

RegionPercentage is like a crop command, but you can specify coordinates outside of the image and thereby add padding. It's like a window.

type Steps

type Steps struct {
	// contains filtered or unexported fields
}

Steps is the builder for creating a operation

func NewStep

func NewStep() Steps

NewStep creates a step that can be used to specify how graph should be processed

func (*Steps) Alpha

func (steps *Steps) Alpha(value float32) *Steps

Alpha histogram area This command is not recommended as it operates in the sRGB space and does not produce perfect results.

func (*Steps) Branch

func (steps *Steps) Branch(f func(*Steps)) *Steps

Branch create a alternate path for the output

func (*Steps) Brightness

func (steps *Steps) Brightness(value float32) *Steps

Brightness histogram area This command is not recommended as it operates in the sRGB space and does not produce perfect results.

func (*Steps) Command

func (steps *Steps) Command(cmd string) *Steps

Command is used to execute query like strings

func (*Steps) Constrain

func (steps *Steps) Constrain(dataMap Constrain) *Steps

Constrain is used to constraint a image

func (*Steps) ConstrainWithin

func (steps *Steps) ConstrainWithin(w float64, h float64) *Steps

ConstrainWithin is used to constraint a image

func (*Steps) ConstrainWithinH

func (steps *Steps) ConstrainWithinH(h float64) *Steps

ConstrainWithinH is used to constraint a image

func (*Steps) ConstrainWithinW

func (steps *Steps) ConstrainWithinW(w float64) *Steps

ConstrainWithinW is used to constraint a image

func (*Steps) Contrast

func (steps *Steps) Contrast(value float32) *Steps

Contrast histogram area This command is not recommended as it operates in the sRGB space and does not produce perfect results.

func (*Steps) CopyRectangle

func (steps *Steps) CopyRectangle(f func(steps *Steps), rect RectangleToCanvas) *Steps

CopyRectangle copy a image

func (*Steps) CropWhitespace

func (steps *Steps) CropWhitespace(threshold int, padding float64) *Steps

CropWhitespace is used to remove whitespace around the image

func (*Steps) Decode

func (steps *Steps) Decode(task ioOperation) *Steps

Decode is used to import a image

func (*Steps) DrawExact

func (steps *Steps) DrawExact(f func(steps *Steps), rect DrawExact) *Steps

DrawExact copy a image

func (*Steps) Encode

func (steps *Steps) Encode(task ioOperation, preset presetInterface) *Steps

Encode is used to convert the image

func (*Steps) Execute

func (steps *Steps) Execute() (map[string][]byte, error)

Execute the graph

func (*Steps) ExpandCanvas

func (steps *Steps) ExpandCanvas(canvas ExpandCanvas) *Steps

ExpandCanvas is used create a rectangle on the image

func (*Steps) FillRect

func (steps *Steps) FillRect(x1 float64, y1 float64, x2 float64, y2 float64, color Color) *Steps

FillRect is used create a rectangle on the image

func (*Steps) FlipH

func (steps *Steps) FlipH() *Steps

FlipH is to used to flip image horizontally

func (*Steps) FlipV

func (steps *Steps) FlipV() *Steps

FlipV is to used to flip image horizontally

func (*Steps) GIF

func (steps *Steps) GIF(operation ioOperation) *Steps

GIF encodes to a gif

func (*Steps) GrayscaleBT709

func (steps *Steps) GrayscaleBT709() *Steps

GrayscaleBT709 histogram area This command is not recommended as it operates in the sRGB space and does not produce perfect results.

func (*Steps) GrayscaleFlat

func (steps *Steps) GrayscaleFlat() *Steps

GrayscaleFlat histogram area This command is not recommended as it operates in the sRGB space and does not produce perfect results.

func (*Steps) GrayscaleNTSC

func (steps *Steps) GrayscaleNTSC() *Steps

GrayscaleNTSC histogram area This command is not recommended as it operates in the sRGB space and does not produce perfect results.

func (*Steps) GrayscaleRY

func (steps *Steps) GrayscaleRY() *Steps

GrayscaleRY histogram area This command is not recommended as it operates in the sRGB space and does not produce perfect results.

func (*Steps) Invert

func (steps *Steps) Invert() *Steps

Invert histogram area This command is not recommended as it operates in the sRGB space and does not produce perfect results.

func (*Steps) JPEG

func (steps *Steps) JPEG(operation ioOperation) *Steps

JPEG encodes to a jpeg

func (*Steps) PNG

func (steps *Steps) PNG(operation ioOperation) *Steps

PNG encodes to a png

func (*Steps) Region

func (steps *Steps) Region(region Region) *Steps

Region is used to crop or add padding to image

func (*Steps) RegionPercentage

func (steps *Steps) RegionPercentage(region RegionPercentage) *Steps

RegionPercentage is used to crop or add padding to image using percentage

func (*Steps) Rotate180

func (steps *Steps) Rotate180() *Steps

Rotate180 is to used to rotate by 180 degrees

func (*Steps) Rotate270

func (steps *Steps) Rotate270() *Steps

Rotate270 is to used to rotate by 270 degrees

func (*Steps) Rotate90

func (steps *Steps) Rotate90() *Steps

Rotate90 is to used to rotate by 90 degrees

func (*Steps) Saturation

func (steps *Steps) Saturation(value float32) *Steps

Saturation histogram area This command is not recommended as it operates in the sRGB space and does not produce perfect results.

func (*Steps) Sepia

func (steps *Steps) Sepia() *Steps

Sepia histogram area This command is not recommended as it operates in the sRGB space and does not produce perfect results.

func (*Steps) ToJSON

func (steps *Steps) ToJSON() []byte

func (*Steps) Watermark

func (steps *Steps) Watermark(data ioOperation, gravity interface{}, fitMode string, fitBox FitBox, opacity float32, hint interface{}) *Steps

Watermark is used to watermark a image

func (*Steps) WebP

func (steps *Steps) WebP(operation ioOperation) *Steps

WebP encodes to a webp

func (*Steps) WhiteBalanceSRGB

func (steps *Steps) WhiteBalanceSRGB(threshold float32) *Steps

WhiteBalanceSRGB histogram area This command is not recommended as it operates in the sRGB space and does not produce perfect results.

type Transparent

type Transparent string

Transparent is the Implementation of interface Color and used as color transparent

type URL

type URL struct {
	// contains filtered or unexported fields
}

URL is used to make a http request to get file and use it

func NewURL

func NewURL(url string) *URL

NewURL is used to create a new url operation

type WebP

type WebP struct {
	Quality int `json:"quality"`
}

WebP is used to encode image using webp encoder

type WebPLossless

type WebPLossless struct{}

WebPLossless is used to encode using webplossless encoder

Jump to

Keyboard shortcuts

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