Documentation
¶
Overview ¶
Package orly implements an parody book cover generator.
A living instance can be found at https://rly.nanmu.me/
Index ¶
Constants ¶
const ( // PaddingPctH padding in milli of width PaddingPctH = 40 // ImageSizePctH image width and height in milli of height ImageSizePctH = 505 // PrimaryBarHPct PrimaryBar Height in milli PrimaryBarHPct = 193 // PrimaryBarPosPctH Y position of primary min point in milli PrimaryBarPosPctH = 573 // SecondaryBarHPct secondaryBar Height in milli SecondaryBarHPct = 14 // Denominator for ratio Denominator = 1e3 // TitleSizePctH1 title font size of cover height in milli TitleSizePctH1 = 105 // TitleSizePctH1Small title font size of cover height in milli for non-CJK input TitleSizePctH1Small = 85 // TitleSizePctH2 title(two lines) font size of cover height in milli TitleSizePctH2 = 55 // TopTextSizePctH TopText font size of cover height in milli TopTextSizePctH = 20 // AuthorSizePctH author font size of cover height in milli AuthorSizePctH = 24 // GuideTextPctH GuideText font size of cover height in milli GuideTextPctH = 28 // FontORLYPctH ORLY font size of cover height in milli FontORLYPctH = 36 )
const ( BottomRight = "BR" BottomLeft = "BL" TopRight = "TR" TopLeft = "TL" )
GuideText Position
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CoverFactory ¶
type CoverFactory struct { // CoverProvider provides cached cover images CoverProvider *ImageProvider // cover prototype CoverPrototype *image.RGBA // contains filtered or unexported fields }
CoverFactory O RLY cover factory
func NewCoverFactory ¶
func NewCoverFactory(width, height int, provider *ImageProvider, titleFont, regularFont, orlyFont *truetype.Font) (c *CoverFactory)
NewCoverFactory initialize the cover
func (*CoverFactory) Draw ¶
func (c *CoverFactory) Draw(title, topText, author, guideText, guideTextPosition string, primaryColor color.Color, imageID int) (img *image.RGBA, err error)
Draw outputs the cover in image
func (*CoverFactory) PreheatCache ¶
func (c *CoverFactory) PreheatCache(maxImageID int) (err error)
PreheatCache loads cover image into cache
type ImageCache ¶
type ImageCache struct {
// contains filtered or unexported fields
}
ImageCache is an in-memory key-value image store
ImageCache is safe for concurrency use.
type ImageProvider ¶
type ImageProvider struct {
// contains filtered or unexported fields
}
ImageProvider is an loader and holder for assets of their various size. If the size asked does not exist, provider will load the origin file from file system, resize it and cache product in memory.
ImageProvider is safe for concurrent use.
For now, ImageProvider does not handle memory growing.
func NewImageProvider ¶
func NewImageProvider(Loader func(fileName string) (image.Image, error)) *ImageProvider
NewImageProvider factory of ImageProvider
func (*ImageProvider) Miss ¶
func (i *ImageProvider) Miss() uint64
Miss report the num of cache miss