Documentation
¶
Overview ¶
The imageflux package builds and parse URLs for ImageFlux.
ImageFlux is Image Conversion & Distribution Engine. This allows you to easily generate images optimized for each device based on a single source image, and delivers them quickly and with high quality.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrExpired = errors.New("imageflux: expired")
ErrExpired is returned when the image is expired.
var ErrInvalidSignature = errors.New("imageflux: invalid signature")
ErrInvalidSignature is returned when the signature is invalid.
Functions ¶
This section is empty.
Types ¶
type AspectMode ¶
type AspectMode int
AspectMode is aspect mode.
const ( // AspectModeDefault is the default value of aspect mode. AspectModeDefault AspectMode = iota // AspectModeScale holds the the aspect ratio of the input image, // and scales to fit in the specified size. AspectModeScale // AspectModeForceScale ignores the aspect ratio of the input image. AspectModeForceScale // AspectModeCrop holds the the aspect ratio of the input image, // and crops the image. AspectModeCrop // AspectModePad holds the the aspect ratio of the input image, // and fills the unfilled portion with the specified background color. AspectModePad )
func (AspectMode) String ¶
func (a AspectMode) String() string
type Config ¶
type Config struct {
// Width is width in pixel of the scaled image.
Width int
// Height is height in pixel of the scaled image.
Height int
// DisableEnlarge disables enlarge.
DisableEnlarge bool
// AspectMode is aspect mode.
AspectMode AspectMode
// DevicePixelRatio is a scale factor of device pixel ratio.
// If DevicePixelRatio is 0, it is ignored.
DevicePixelRatio float64
// InputClip is a position in pixel of clipping area.
// This is used for the input image.
InputClip image.Rectangle
// InputClipRatio is a position in ratio of clipping area.
// The coordinates of the rectangle are divided by ClipMax.X or ClipMax.Y.
// This is used for the input image.
InputClipRatio image.Rectangle
// InputOrigin is the position of the input image origin.
InputOrigin Origin
// OutputClip is a position in pixel of clipping area.
// This is used for the output image.
OutputClip image.Rectangle
// Clip is an alias of OutputClip.
// If both Clip and OutputClip are set, OutputClip is used.
//
// Deprecated: Use OutputClip instead.
Clip image.Rectangle
// OutputClipRatio is a position in ratio of clipping area.
// The coordinates of the rectangle are divided by ClipMax.X or ClipMax.Y.
OutputClipRatio image.Rectangle
// ClipRatio is an alias of OutputClipRatio.
// If both ClipRatio and OutputClipRatio are set, OutputClipRatio is used.
//
// Deprecated: Use OutputClipRatio instead.
ClipRatio image.Rectangle
// OutputOrigin is the position of the output image origin.
OutputOrigin Origin
// ClipMax is the denominators of ClipRatio.
ClipMax image.Point
// Origin is the position of the image origin.
Origin Origin
// Background is background color.
Background color.Color
// InputRotate rotates the image before processing.
InputRotate Rotate
// OutputRotate rotates the image after processing.
OutputRotate Rotate
// OutputRotate rotates the image after processing.
// This is an alias of OutputRotate.
// If both Rotate and OutputRotate are set, OutputRotate is used.
//
// Deprecated: Use OutputRotate instead.
Rotate Rotate
// Through is a format to pass through.
Through Through
// Overlay Parameters.
Overlays []*Overlay
// Output Parameters.
Format Format
// Quality is quality of the output image.
// It is used when the output format is JPEG or WebP.
Quality int
// DisableOptimization disables optimization of the Huffman coding table
// of the output image when the output format is JPEG.
DisableOptimization bool
// Lossless enables lossless compression when the output format is WebP.
Lossless bool
// ExifOption specifies the Exif information to be included in the output image.
ExifOption ExifOption
// Unsharp configures unsharp mask.
Unsharp Unsharp
// Blur configures blur.
Blur Blur
// GrayScale converts to gray scale.
// 0 means no conversion and 100 means full conversion.
GrayScale int
// Sepia converts to sepia.
// 0 means no conversion and 100 means full conversion.
Sepia int
// Brightness adjusts brightness.
// The value set in Brightness plus 100 is actually used.
Brightness int
// Contrast adjusts contrast.
// The value set in Contrast plus 100 is actually used.
Contrast int
// Invert inverts the image if it is true.
Invert bool
}
Config is configure of image.
func ParseConfig ¶ added in v1.2.0
type ExifOption ¶ added in v1.2.0
type ExifOption int
ExifOption specifies the Exif information to be included in the output image.
const ( // ExifOptionDefault is the default value of ExifOption. ExifOptionDefault ExifOption = 0 // ExifOptionStrip removes all Exif information from the output image. ExifOptionStrip ExifOption = 1 // ExifOptionKeepOrientation removes all Exif information // except Orientation from the output image. ExifOptionKeepOrientation ExifOption = 2 )
type Format ¶
type Format string
Format is the format of the output image.
const ( // FormatAuto encodes the image by the same format with the input image. FormatAuto Format = "auto" // FormatJPEG encodes the image as JPEG. FormatJPEG Format = "jpg" // FormatPNG encodes the image as PNG. FormatPNG Format = "png" // FormatGIF encodes the image as GIF. FormatGIF Format = "gif" // FormatWebP encodes the image as WebP. FormatWebP Format = "webp" // FormatWebPAuto encodes the image as a WebP if the client supports WebP. // Otherwise, the image is encoded as the same format with the input image. FormatWebPAuto Format = "webp:auto" // FormatWebPJPEG encodes the image as a WebP if the client supports WebP. // Otherwise, the image is encoded as JPEG. FormatWebPJPEG Format = "webp:jpg" // FormatWebPPNG encodes the image as a WebP if the client supports WebP. // Otherwise, the image is encoded as PNG. FormatWebPPNG Format = "webp:png" // FormatWebPGIF encodes the image as a WebP if the client supports WebP. // Otherwise, the image is encoded as GIF. FormatWebPGIF Format = "webp:gif" // FormatWebPFromJPEG encodes the image as a WebP. // // Deprecated: use FormatWebPJPEG instead. FormatWebPFromJPEG Format = "webp:jpeg" // FormatWebPFromPNG encodes the image as a WebP. // // Deprecated: use FormatWebPPNG instead. FormatWebPFromPNG Format = "webp:png" )
type Image ¶
type Image struct {
// Path is the path of the image.
Path string
// Proxy is the proxy server.
Proxy *Proxy
// Config is the configuration of
// converting the image.
Config *Config
// Expires is the expiration time of the url
// generated by String and SignedURL.
// If Expires is zero, the url does not expire.
Expires time.Time
}
Image is an image served via ImageFlux.
func (*Image) SignedURL ¶
SignedURL returns the URL of the image with the signature.
Example ¶
proxy := &imageflux.Proxy{
Host: "demo.imageflux.jp",
}
cfg := &imageflux.Config{
// resize the image to 200px width.
Width: 200,
// convert the image to WebP format.
Format: imageflux.FormatWebPAuto,
}
u := proxy.Image("/images/1.jpg", cfg).SignedURL()
fmt.Println(u)
Output: https://demo.imageflux.jp/c/w=200,f=webp:auto/images/1.jpg
Example (Signed) ¶
proxy := &imageflux.Proxy{
Host: "demo.imageflux.jp",
Secret: "testsigningsecret",
}
cfg := &imageflux.Config{
// resize the image to 200px width.
Width: 200,
}
u := proxy.Image("/images/1.jpg", cfg).SignedURL()
fmt.Println(u)
Output: https://demo.imageflux.jp/c/sig=1.tiKX5u2kw6wp9zDgl1tLiOIi8IsoRIBw8fVgVc0yrNg=,w=200/images/1.jpg
func (*Image) SignedURLWithoutComma ¶ added in v1.2.0
SignedURLWithoutComma is same as SignedURL but the url doesn't contain comma. It is useful for srcset of HTML img tag.
Example ¶
proxy := &imageflux.Proxy{
Host: "demo.imageflux.jp",
}
cfg := &imageflux.Config{
// resize the image to 200px width.
Width: 200,
// convert the image to WebP format.
Format: imageflux.FormatWebPAuto,
}
u := proxy.Image("/images/1.jpg", cfg).SignedURLWithoutComma()
fmt.Println(u)
Output: https://demo.imageflux.jp/c/w=200%2Cf=webp:auto/images/1.jpg
type MaskType ¶ added in v1.2.0
type MaskType string
MaskType specifies the area to be treated as a mask.
type Origin ¶
type Origin int
Origin is the origin.
const ( // OriginDefault is default origin. OriginDefault Origin = 0 // OriginTopLeft is top-left OriginTopLeft Origin = 1 // OriginTopCenter is top-center OriginTopCenter Origin = 2 // OriginTopRight is top-right OriginTopRight Origin = 3 // OriginMiddleLeft is middle-left OriginMiddleLeft Origin = 4 // OriginMiddleCenter is middle-center OriginMiddleCenter Origin = 5 // OriginMiddleRight is middle-right OriginMiddleRight Origin = 6 // OriginBottomLeft is bottom-left OriginBottomLeft Origin = 7 // OriginBottomCenter is bottom-center OriginBottomCenter Origin = 8 // OriginBottomRight is bottom-right OriginBottomRight Origin = 9 )
type Overlay ¶
type Overlay struct {
// Path is a path for overlay image.
Path string
// URL is an url for overlay image.
//
// Deprecated: Use Path instead.
URL string
// Width is width in pixel of the scaled image.
Width int
// Height is height in pixel of the scaled image.
Height int
// DisableEnlarge disables enlarge.
DisableEnlarge bool
// AspectMode is aspect mode.
AspectMode AspectMode
// InputClip is a position in pixel of clipping area.
// This is used for the input image.
InputClip image.Rectangle
// InputClipRatio is a position in ratio of clipping area.
// The coordinates of the rectangle are divided by ClipMax.X or ClipMax.Y.
// This is used for the input image.
InputClipRatio image.Rectangle
// InputOrigin is the position of the input image origin.
InputOrigin Origin
// OutputClip is a position in pixel of clipping area.
// This is used for the output image.
OutputClip image.Rectangle
// Clip is an alias of OutputClip.
// If both Clip and OutputClip are set, OutputClip is used.
//
// Deprecated: Use OutputClip instead.
Clip image.Rectangle
// OutputClipRatio is a position in ratio of clipping area.
// The coordinates of the rectangle are divided by ClipMax.X or ClipMax.Y.
OutputClipRatio image.Rectangle
// ClipRatio is an alias of OutputClipRatio.
// If both ClipRatio and OutputClipRatio are set, OutputClipRatio is used.
//
// Deprecated: Use OutputClipRatio instead.
ClipRatio image.Rectangle
// OutputOrigin is the position of the output image origin.
OutputOrigin Origin
// ClipMax is the denominators of ClipRatio.
ClipMax image.Point
// Origin is the position of the image origin.
Origin Origin
// Background is background color.
Background color.Color
// InputRotate rotates the image before processing.
InputRotate Rotate
// OutputRotate rotates the image after processing.
OutputRotate Rotate
// OutputRotate rotates the image after processing.
// This is an alias of OutputRotate.
// If both Rotate and OutputRotate are set, OutputRotate is used.
//
// Deprecated: Use OutputRotate instead.
Rotate Rotate
// Offset is an offset in pixel of overlay image.
Offset image.Point
// OffsetRatio is an offset in ratio of overlay image.
// The coordinates of the rectangle are divided by OffsetMax.X or OffsetMax.Y.
OffsetRatio image.Point
// OffsetMax is the denominators of OffsetRatio.
OffsetMax image.Point
// OverlayOrigin is the position of the overlay image origin.
OverlayOrigin Origin
// MaskType specifies the area to be treated as a mask.
MaskType MaskType
// PaddingMode specifies processing when the specified image is smaller than the input image.
PaddingMode PaddingMode
}
Overlay is the configure of an overlay image.
func ParseOverlay ¶ added in v1.2.0
ParseOverlay parses an overlay image.
type PaddingMode ¶ added in v1.2.0
type PaddingMode int
PaddingMode specifies processing when the specified image is smaller than the input image.
const ( // PaddingModeDefault makes the part of the image that protrudes from the specified image transparent. PaddingModeDefault PaddingMode = 0 // PaddingModeLeave leaves the overflow area of the specified image as it is. PaddingModeLeave PaddingMode = 1 )
type Proxy ¶
Proxy is a proxy of ImageFlux.
func (*Proxy) Parse ¶ added in v1.2.0
Parse parses the path and returns the image.
Example ¶
proxy := &imageflux.Proxy{}
image, err := proxy.Parse("/c/w=200/images/1.jpg", "")
if err != nil {
log.Fatal(err)
}
fmt.Printf("path = %s\n", image.Path)
fmt.Printf("width = %d\n", image.Config.Width)
Output: path = /images/1.jpg width = 200
Example (Signed) ¶
proxy := &imageflux.Proxy{
Secret: "testsigningsecret",
}
image, err := proxy.Parse("/c/w=200/images/1.jpg", "1.tiKX5u2kw6wp9zDgl1tLiOIi8IsoRIBw8fVgVc0yrNg=")
if err != nil {
log.Fatal(err)
}
fmt.Printf("path = %s\n", image.Path)
fmt.Printf("width = %d\n", image.Config.Width)
Output: path = /images/1.jpg width = 200
type Rotate ¶
type Rotate int
Rotate rotates the image.
const ( // RotateDefault is the default value of Rotate. // It is same effect as RotateTopLeft. RotateDefault Rotate = 0 // RotateTopLeft does not anything. RotateTopLeft Rotate = 1 // RotateTopRight flips the image left and right. RotateTopRight Rotate = 2 // RotateBottomRight rotates the image 180 degrees. RotateBottomRight Rotate = 3 // RotateBottomLeft flips the image upside down. RotateBottomLeft Rotate = 4 // RotateLeftTop mirrors the image around the diagonal axis. RotateLeftTop Rotate = 5 // RotateRightTop rotates the image left 90 degrees. RotateRightTop Rotate = 6 // RotateRightBottom rotates the image 180 degrees and mirrors the image around the diagonal axis. RotateRightBottom Rotate = 7 // RotateLeftBottom rotates the image right 90 degrees. RotateLeftBottom Rotate = 8 // RotateAuto parses the Orientation of the Exif information and rotates the image. RotateAuto Rotate = -1 )