cogen

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

Cogen

Cogen is an automatic article cover generation tool, which can generate article covers according to requirements after configuring relevant options.

Installation

To install this package, you need to install Go and set your Go workspace first.

  1. You first need Go installed, then you can use the below Go command to install Cogen.
go get -u github.com/LgoLgo/cogen
  1. Import it in your code:
import "github.com/LgoLgo/cogen"

Example

package main

import "github.com/LgoLgo/cogen"

func main() {
	cogen.CoverGen(
		cogen.WithTitle("How to generate an article cover by golang"),
		cogen.WithImagePath("example/gopher.png"),
		cogen.WithFontFilePath("font/zads.ttf"),
		cogen.WithFontRGB([]int{0, 0, 0}),
		cogen.WithCoverRGB([]int{250, 235, 215}),
		cogen.WithFontSize(100),
	)
}

Output

result

Options

Option Default Description
Title LgoLgo Title sets article title.
SavingFileName LgoLgo SavingFileName sets file name.
FontFilePath font/syqh.ttf FontFilePath sets font file path. There are other fonts in the font folder. If you need to use them, just configure their paths.
ImagePath LgoLgo.png ImagePath sets image path. The image will appear on the left side of the cover.
CoverRGB []int{47, 54, 66} CoverRGB sets cover's RGB255.
FontRGB []int{238, 241, 247} FontRGB sets font's RGB255.
FontSize 76 FontSize sets font size.
DPI 72 DPI sets font's DPI.
LineSpacing 1.1 LineSpacing sets line spacing.
Width 1343 Width sets cover width.
ResizeWidth 1000 ResizeWidth sets image width.
MaxWordWidth 660.0 MaxWordWidth sets max word's width.
Height 734 Height sets height.
ResizeHeight 500 ResizeHeight sets image height.
X 800.0 X sets font's X coordinate.
AX 0.5 AX sets font's AX.
AnchoredX 200 AnchoredX sets image's X coordinate.
AnchoredAX 0.5 AnchoredAX set image's AX.
Y 300.0 Y sets font's Y coordinate.
AY 0.6 AY sets font's AY.
AnchoredY 220 AnchoredY sets image's Y coordinate.
AnchoredAY 0.5 AnchoredAY set image's AY.

License

This project is under the Apache License 2.0. See the LICENSE file for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OptionsDefault = Options{
	Title:          "LgoLgo",
	SavingFileName: "LgoLgo",
	FontFilePath:   "font/syqh.ttf",
	ImagePath:      "img/gopher.png",
	CoverRGB:       []int{47, 54, 66},
	FontRGB:        []int{238, 241, 247},
	FontSize:       76,
	DPI:            72,
	LineSpacing:    1.1,
	Width:          1343,
	ResizeWidth:    1000,
	MaxWordWidth:   660.0,
	Height:         734,
	ResizeHeight:   500,
	X:              800.0,
	AX:             0.5,
	AnchoredX:      200,
	AnchoredAX:     0.5,
	Y:              300.0,
	AY:             0.6,
	AnchoredY:      220,
	AnchoredAY:     0.5,
}

OptionsDefault is the default options.

Functions

func CoverGen

func CoverGen(opts ...Option)

Types

type Option

type Option struct {
	F func(o *Options)
}

Option is the only struct that can be used to set Options.

func WithAX

func WithAX(ax float64) Option

WithAX sets font's AX.

func WithAY

func WithAY(ay float64) Option

WithAY sets font's AY.

func WithAnchoredAX

func WithAnchoredAX(ax float64) Option

WithAnchoredAX sets image's AX.

func WithAnchoredAY

func WithAnchoredAY(ay float64) Option

WithAnchoredAY sets image's AY.

func WithAnchoredX

func WithAnchoredX(x int) Option

WithAnchoredX sets image's X coordinate.

func WithAnchoredY

func WithAnchoredY(y int) Option

WithAnchoredY sets image's Y coordinate.

func WithCoverRGB

func WithCoverRGB(rgb []int) Option

WithCoverRGB sets cover's RGB255.

func WithDPI

func WithDPI(dpi float64) Option

WithDPI sets font's DPI.

func WithFontFilePath

func WithFontFilePath(path string) Option

WithFontFilePath sets font file path.

func WithFontRGB

func WithFontRGB(rgb []int) Option

WithFontRGB sets font's RGB255.

func WithFontSize

func WithFontSize(size float64) Option

WithFontSize sets font's size.

func WithHeight

func WithHeight(height int) Option

WithHeight sets cover's height.

func WithImagePath

func WithImagePath(path string) Option

WithImagePath sets image path.

func WithLineSpacing

func WithLineSpacing(lineSpacing float64) Option

WithLineSpacing sets line spacing.

func WithMaxWordWidth

func WithMaxWordWidth(width float64) Option

WithMaxWordWidth sets max word width.

func WithResizeHeight

func WithResizeHeight(height int) Option

WithResizeHeight sets image's height.

func WithResizeWidth

func WithResizeWidth(width int) Option

WithResizeWidth sets image's width.

func WithSavingFileName

func WithSavingFileName(savingFileName string) Option

WithSavingFileName sets title.

func WithTitle

func WithTitle(title string) Option

WithTitle sets title.

func WithWidth

func WithWidth(width int) Option

WithWidth sets cover's width.

func WithX

func WithX(x float64) Option

WithX sets font's X coordinate.

func WithY

func WithY(y float64) Option

WithY sets font's Y coordinate.

type Options

type Options struct {
	// Title sets article title.
	//
	// Default: LgoLgo
	Title string

	// SavingFileName sets file name.
	//
	// Default: LgoLgo
	SavingFileName string

	// FontFilePath sets font file path.
	//
	// Default: font/syqh.ttf
	FontFilePath string

	// ImagePath sets image path
	//
	// Default: img/gopher.png
	ImagePath string

	// CoverRGB sets cover's RGB255.
	//
	// Default: []int{47, 54, 66}
	CoverRGB []int

	// FontRGB sets font's RGB255.
	//
	// Default: []int{238, 241, 247}
	FontRGB []int

	// FontSize sets font size.
	//
	//Default: 76
	FontSize float64

	// DPI sets font's DPI.
	//
	// Default: 72
	DPI float64

	// LineSpacing sets line spacing.
	//
	// Default: 1.1
	LineSpacing float64

	// Width sets cover width.
	//
	// Default: 1343
	Width int

	// ResizeWidth sets image width.
	//
	// Default: 1000
	ResizeWidth int

	// MaxWordWidth sets max word's width.
	//
	// Default: 660.0
	MaxWordWidth float64

	// Height sets height.
	//
	// Default: 734
	Height int

	// ResizeHeight sets image height.
	//
	// Default: 500
	ResizeHeight int

	// X sets font's X coordinate.
	//
	// Default: 800.0
	X float64

	// AX sets font's AX.
	//
	// Default: 0.5
	AX float64

	// AnchoredX sets image's X coordinate.
	//
	// Default: 200
	AnchoredX int

	// AnchoredAX set image's AX.
	//
	// Default: 0.5
	AnchoredAX float64

	// Y sets font's Y coordinate.
	//
	// Default: 300.0
	Y float64

	// AY sets font's AY.
	//
	// Default: 0.6
	AY float64

	// AnchoredY sets image's Y coordinate.
	//
	// Default: 220
	AnchoredY int

	// AnchoredAY set image's AY.
	//
	// Default: 0.5
	AnchoredAY float64
}

func NewOptions

func NewOptions(opts ...Option) *Options

func (*Options) Apply

func (o *Options) Apply(opts []Option)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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