ilibgo

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

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

Go to latest
Published: Sep 1, 2022 License: LGPL-2.1 Imports: 18 Imported by: 0

README

Ilib - Image Library for Go

Copyright (C) 2001-2022 Craig Knudsen, craig@k5n.us http://github.com/craigk5n/ilibgo

Ilib is a library (and some tools and examples) written in Go that can read, create, manipulate and save images. It is capable of using X11 BDF fonts for drawing text. That means you get lots of fonts to use. You can even create your own if you know how to create an X11 BDF font. It should be able to read any image file that the base Go image package supports.

History

This code was ported to Go from the original version in C. The API remains very close to the original C code. All the functions dropped the "I" at the start since Go supports namespaces. The original C library was modeled after the X11 functions, documented here as man pages.

BDF Fonts

Additional BDF Fonts can be found at: https://gitlab.freedesktop.org/xorg/font

Note that fonts can be loaded as external fonts at run-time, or fonts can be embedded in the binary by using the bdftogo tool included in this package.

Note that some of the BDF fonts are bundled with this package. Please see the COPYING notice

Copyright 1984-1989, 1994 Adobe Systems Incorporated. Copyright 1988, 1994 Digital Equipment Corporation.

Adobe is a trademark of Adobe Systems Incorporated which may be registered in certain jurisdictions. Permission to use these trademarks is hereby granted only in association with the images described in this file.

Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notices appear in all copies and that both those copyright notices and this permission notice appear in supporting documentation, and that the names of Adobe Systems and Digital Equipment Corporation not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Adobe Systems and Digital Equipment Corporation make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.

Edit/Import/Create BDF fonts with FontForge.

Building

go build

History

See ChangeLog

Documentation

Overview

Image Library for Go

Ilib is a library (and some tools and examples) written in Go that can read, create, manipulate and save images. It is capable of using X11 BDF fonts for drawing text. That means you get lots of fonts to use. You can even create your own if you know how to create an X11 BDF font. It should be able to read any image file that the base Go image package supports. Copyright (C) 2001-2022 Craig Knudsen, craig@k5n.us http://github.com/craigk5n/ilibgo

Index

Constants

View Source
const (
	DefaultFormatString = "ppm"
	IlibVersion         = "2.0"
	IlibVersionDate     = "11 Aug 2022"

	FormatGIF       ImageFormat = 0
	FormatPPM       ImageFormat = 1
	FormatPGM       ImageFormat = 2
	FormatPBM       ImageFormat = 3
	FormatXPM       ImageFormat = 4
	FormatXBM       ImageFormat = 5
	FormatPNG       ImageFormat = 6
	FormatJPEG      ImageFormat = 7
	FormatTIFF      ImageFormat = 8
	FormatBMP       ImageFormat = 9
	NumberOfFormats uint        = 10
)
View Source
const BlackPixel int = 0

Default color values

View Source
const WhitePixel int = 1

Variables

This section is empty.

Functions

func CopyImage

func CopyImage(source *Image, dest *Image, gc GraphicsContext, src_x int, src_y int, width int, height int,
	dest_x int, dest_y int) error

Copy a rectangle portion of a source image to a destination image

func CopyImageScaled

func CopyImageScaled(source *Image, dest *Image,
	src_x int, src_y int, src_width int, src_height int,
	dest_x int, dest_y int, dest_width int, dest_height int) error

This allows the user to scale up or down the source image onto the destination image.

func DrawLine

func DrawLine(image *Image, gc GraphicsContext, x1 int, y1 int, x2 int, y2 int) error

func DrawPoint

func DrawPoint(image *Image, gc GraphicsContext, x int, y int) error

Set the point at the specified location using the foreground color of the IGC parameter. (This is an alias to ISetPoint.)

func DrawPolygon

func DrawPolygon(image *Image, gc GraphicsContext, points []Point) error

func DrawRectangle

func DrawRectangle(image *Image, gc GraphicsContext, x int, y int, width int, height int) error

Draw a rectangle

func DrawString

func DrawString(image *Image, gc GraphicsContext, x int, y int, text string)

func DrawStringRotated

func DrawStringRotated(image *Image, gc GraphicsContext, x int, y int, text string, direction TextDirection)

func DrawStringRotatedAngle

func DrawStringRotatedAngle(image *Image, gc GraphicsContext, x int, y int, text string, angle float64)

func FillPolygon

func FillPolygon(image *Image, gc GraphicsContext, points []Point) error

Fill a polygonn

func FillRectangle

func FillRectangle(image *Image, gc GraphicsContext, x int, y int, width int, height int) error

Draw a filled rectangle

func FloodFill

func FloodFill(image *Image, gc GraphicsContext, x int, y int) error

func GetFontSize

func GetFontSize(font *Font) (height int, err error)

func IDrawArc

func IDrawArc(image *Image, gc GraphicsContext, x int, y int, r1 int, r2 int, a1 float64, a2 float64) error

Draw an arc. Both arc1 and arc2 are in degrees from 0 to 360.

func IDrawCircle

func IDrawCircle(image *Image, gc GraphicsContext, x int, y int, r int) error

Draw a circle

func IDrawEllipse

func IDrawEllipse(image *Image, gc GraphicsContext, x int, y int, r1 int, r2 int) error

func IDrawEnclosedArc

func IDrawEnclosedArc(image *Image, gc GraphicsContext, x int, y int, r1 int, r2 int, a1 float64, a2 float64) error

Draw an arc and connect it to the center point.

func IFillArc

func IFillArc(image *Image, gc GraphicsContext, x int, y int, r1 int, r2 int, a1 float64, a2 float64) error

Fill an arc

func IFillCircle

func IFillCircle(image *Image, gc GraphicsContext, x int, y int, r int) error

Fill a circle

func ImageHeight

func ImageHeight(img *Image) int

func ImageWidth

func ImageWidth(img *Image) int

func IsSupportedFormat

func IsSupportedFormat(stringFormat string) bool

Check to see if the specified image format (as represented as the file suffix like "png") is supported. Some image formats

func SetBackground

func SetBackground(gc *GraphicsContext, backgroundColor Color)

func SetFont

func SetFont(gc *GraphicsContext, font *Font)

func SetForeground

func SetForeground(gc *GraphicsContext, foregroundColor Color)

func SetLineStyle

func SetLineStyle(gc *GraphicsContext, lineStyle LineStyle)

func SetLineWidth

func SetLineWidth(gc *GraphicsContext, lineWidth int)

func SetPoint

func SetPoint(image *Image, gc GraphicsContext, x int, y int) error

Set the point at the specified location using the foreground color of the IGC parameter.

func SetTextStyle

func SetTextStyle(gc *GraphicsContext, textStyle TextStyle)

func TextDimensions

func TextDimensions(gc GraphicsContext, font *Font, text string) (width int, height int, err error)

func TextHeight

func TextHeight(gc GraphicsContext, font *Font, text string) (height int, err error)

Get the height (in pixels) of the specified text using the font currently set in the graphics context.

func TextWidth

func TextWidth(gc GraphicsContext, font *Font, text string) (width int, err error)

Get the width (in pixels) of the specified text using the font currently set in the graphics context.

func WriteImageFile

func WriteImageFile(f *os.File, img *Image, format ImageFormat) error

Writes an image to a file. The file is left open for the caller to close.

Types

type BdfChar

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

func FontBDFGetChar

func FontBDFGetChar(font *BdfFont, ch string) (char *BdfChar)

Get the BdfChar value for the specified letter. Note: Only tested on ASCII with English so far.

func FontBDFGetRune

func FontBDFGetRune(font *BdfFont, ch rune) (char *BdfChar)

Get the BdfChar value for the specified letter. Note: Only tested on ASCII with English so far.

type BdfFont

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

type Color

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

func AllocColor

func AllocColor(red, green, blue uint8) (Color, error)

Allocate a color (with no alpha) from RGB values 0-255.

func AllocNamedColor

func AllocNamedColor(name string) (Color, error)

Allocate a color (with no alpha) by its name (e.g. "red", "blue", etc)

func GetPoint

func GetPoint(image *Image, x int, y int) Color

Get the color at a specific point.

type FillStyle

type FillStyle int

Fill styles for use with FillStyle

const (
	FillSolid          FillStyle = 1 // default
	FillTiled          FillStyle = 2 // Not yet implemented
	FillStippled       FillStyle = 3 // Not yet implemented
	FillOpaqueStippled FillStyle = 4 // Not yet implemented
)

type Font

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

func LoadFontFromData

func LoadFontFromData(name string, lines []string) (*Font, error)

Parse the array of string lines that represent the BDF font. Example usage: LoadFontFromData("timR12", font_timR12)

func LoadFontFromFile

func LoadFontFromFile(path string, name string) (*Font, error)

Parse a BFF font file. Example usage: LoadFontFromFile("timR12.bdf", "timR12")

type GraphicsContext

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

func CreateGraphicsContext

func CreateGraphicsContext() GraphicsContext

Create a graphics context

type Image

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

func CreateImage

func CreateImage(width int, height int) *Image

func CreateImageWithBackground

func CreateImageWithBackground(width int, height int, background Color) *Image

func ReadImageFile

func ReadImageFile(f *os.File) (*Image, error)

Creates an image from an image file. The file is left open for the caller to close.

type ImageFormat

type ImageFormat uint8

func FileType

func FileType(filename string) (ImageFormat, error)

func FormatStringToType

func FormatStringToType(formatString string) (ImageFormat, error)

Convert a string representation of an image format (typically the file extension like "png"), and convert it to the corresponding IImageFormat type. An error is returned if the type is not recognized or not supported.

type ImageOption

type ImageOption uint8
const (
	OptionNone       ImageOption = 0
	OptionGrayscale  ImageOption = 1
	OptionGreyscale  ImageOption = OptionGrayscale
	OptionAscii      ImageOption = 2 // ascii output for pbm/pgm/ppm images
	OptionInterlaced ImageOption = 4 // interlaced output (GIF)
)

type LineStyle

type LineStyle int

Line styles for use in LineStyle

const (
	LineSolid      LineStyle = 1 // default
	LineOnOffDash  LineStyle = 2 // Not yet implemented
	LineDoubleDash LineStyle = 3 // Not yet implemented
)

type Point

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

type TextDirection

type TextDirection int
const (
	TextLeftToRight TextDirection = 1 // default
	TextBottomToTop TextDirection = 2
	TextTopToBottom TextDirection = 3
)

type TextStyle

type TextStyle int
const (
	TextNormal    TextStyle = 1 // default
	TextEtchedIn  TextStyle = 2 // text appears etched into background
	TextEtchedOut TextStyle = 3 // text appears etched out of background
	TextShadowed  TextStyle = 4 // text has drop shadow that fades into background
)

Directories

Path Synopsis
Create an go file from a BDF font file so that the BDF font can be bundled with the Go file.
Create an go file from a BDF font file so that the BDF font can be bundled with the Go file.
Create a PNG file that displays the font for ASCII values up to 255.
Create a PNG file that displays the font for ASCII values up to 255.
fonts
Sample app for ilibgo package.
Sample app for ilibgo package.
Build an image that contains an index of a bunch of images.
Build an image that contains an index of a bunch of images.
Report generator for apache2 access.log file
Report generator for apache2 access.log file

Jump to

Keyboard shortcuts

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