Documentation ¶
Overview ¶
Example ¶
package main import ( "io" "log" "github.com/sunshineplan/imgconv" ) func main() { // Open a test image. src, err := imgconv.Open("testdata/video-001.png") if err != nil { log.Fatalf("failed to open image: %v", err) } // Resize the image to width = 200px preserving the aspect ratio. mark := imgconv.Resize(src, imgconv.ResizeOption{Width: 200}) // Add random watermark set opacity = 128. dst := imgconv.Watermark(src, imgconv.WatermarkOption{Mark: mark, Opacity: 128, Random: true}) // Write the resulting image as TIFF. err = imgconv.Write(io.Discard, dst, imgconv.FormatOption{Format: imgconv.TIFF}) if err != nil { log.Fatalf("failed to write image: %v", err) } }
Output:
Index ¶
- func Decode(r io.Reader) (image.Image, error)
- func DecodeConfig(r io.Reader) (image.Config, string, error)
- func Open(file string) (image.Image, error)
- func Resize(base image.Image, option ResizeOption) image.Image
- func Save(output string, base image.Image, option FormatOption) error
- func ToGray(img image.Image) image.Image
- func Watermark(base image.Image, option WatermarkOption) image.Image
- func Write(w io.Writer, base image.Image, option FormatOption) error
- type EncodeOption
- func GIFDrawer(drawer draw.Drawer) EncodeOption
- func GIFNumColors(numColors int) EncodeOption
- func GIFQuantizer(quantizer draw.Quantizer) EncodeOption
- func PNGCompressionLevel(level png.CompressionLevel) EncodeOption
- func Quality(quality int) EncodeOption
- func TIFFCompressionType(compressionType TIFFCompression) EncodeOption
- type Format
- type FormatOption
- type Options
- func (opts *Options) Convert(w io.Writer, base image.Image) error
- func (opts *Options) ConvertExt(filename string) string
- func (opts *Options) SetFormat(f string, options ...EncodeOption) (err error)
- func (opts *Options) SetGray(gray bool) *Options
- func (opts *Options) SetResize(width, height int, percent float64) *Options
- func (opts *Options) SetWatermark(mark image.Image, opacity uint) *Options
- type ResizeOption
- type TIFFCompression
- type WatermarkOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeConfig ¶
DecodeConfig decodes the color model and dimensions of an image that has been encoded in a registered format. The string returned is the format name used during format registration.
func Resize ¶
func Resize(base image.Image, option ResizeOption) image.Image
Resize add watermark to image
func Save ¶
func Save(output string, base image.Image, option FormatOption) error
Save saves image according format option
Types ¶
type EncodeOption ¶
type EncodeOption func(*encodeConfig)
EncodeOption sets an optional parameter for the Encode and Save functions. https://github.com/disintegration/imaging
func GIFDrawer ¶
func GIFDrawer(drawer draw.Drawer) EncodeOption
GIFDrawer returns an EncodeOption that sets the drawer that is used to convert the source image to the desired palette of the GIF-encoded image.
func GIFNumColors ¶
func GIFNumColors(numColors int) EncodeOption
GIFNumColors returns an EncodeOption that sets the maximum number of colors used in the GIF-encoded image. It ranges from 1 to 256. Default is 256.
func GIFQuantizer ¶
func GIFQuantizer(quantizer draw.Quantizer) EncodeOption
GIFQuantizer returns an EncodeOption that sets the quantizer that is used to produce a palette of the GIF-encoded image.
func PNGCompressionLevel ¶
func PNGCompressionLevel(level png.CompressionLevel) EncodeOption
PNGCompressionLevel returns an EncodeOption that sets the compression level of the PNG-encoded image. Default is png.DefaultCompression.
func Quality ¶
func Quality(quality int) EncodeOption
Quality returns an EncodeOption that sets the output JPEG or PDF quality. Quality ranges from 1 to 100 inclusive, higher is better.
func TIFFCompressionType ¶
func TIFFCompressionType(compressionType TIFFCompression) EncodeOption
TIFFCompressionType returns an EncodeOption that sets the compression type of the TIFF-encoded image. Default is tiff.Deflate.
type Format ¶
type Format int
Format is an image file format.
func FormatFromExtension ¶
FormatFromExtension parses image format from filename extension: "jpg" (or "jpeg"), "png", "gif", "tif" (or "tiff"), "bmp" and "pdf" are supported.
type FormatOption ¶
type FormatOption struct { Format Format EncodeOption []EncodeOption }
FormatOption is format option
type Options ¶
type Options struct { Watermark *WatermarkOption Resize *ResizeOption Format FormatOption Gray bool }
Options represents options that can be used to configure a image operation.
func (*Options) ConvertExt ¶
ConvertExt convert filename's ext according image format.
func (*Options) SetFormat ¶
func (opts *Options) SetFormat(f string, options ...EncodeOption) (err error)
SetFormat sets the value for the Format field.
type ResizeOption ¶
ResizeOption is resize option
type TIFFCompression ¶ added in v1.0.2
type TIFFCompression int
TIFFCompression describes the type of compression used in Options.
const ( TIFFUncompressed TIFFCompression = iota TIFFDeflate TIFFLZW TIFFCCITTGroup3 TIFFCCITTGroup4 TIFFJPEG )
Constants for supported TIFF compression types.
type WatermarkOption ¶
WatermarkOption is watermark option
func (*WatermarkOption) SetOffset ¶
func (w *WatermarkOption) SetOffset(offset image.Point) *WatermarkOption
SetOffset sets the option for the Watermark offset base center when adding fixed watermark.
func (*WatermarkOption) SetRandom ¶
func (w *WatermarkOption) SetRandom(random bool) *WatermarkOption
SetRandom sets the option for the Watermark position random or not.