orly

package module
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2021 License: MIT Imports: 17 Imported by: 0

README

English | 中文

Build Status Lint Status Docker Image Go Report Card GoDoc

O'RLY Cover Generator

O'RLY Cover Generator is a parody book cover generator, implemented in Golang and Vue.js, supporting a wide range of language including CJK.

Go to the living demo to build your own O'RLY cover and troll your friends and colleagues.

Docker images can be found here.

Docker Image

docker pull nanmu42/orly:[tag]

Refer to https://hub.docker.com/r/nanmu42/orly/tags for available tags.

Example config:

CoverImageDir = "cover-images"
Debug = false
MaxImageID = 41
Port = ":3000"
TitleFont = "fonts/SourceHanSerif-Bold.ttc"
NormalFont = "fonts/SourceHanSans-Medium.ttc"
ORLYFont = "fonts/SourceSansPro-Black.ttf"
QueueLen = 20
WorkerNum = 2
Width = 1000

Save as rly.toml, mount it into /app/config, and run docker image with param /app/rly -config config/rly.toml.

Develop O'RLY

O'RLY can be built in following commands:

mkdir -p assets
cd assets
wget -nc https://github.com/nanmu42/orly/releases/download/1.5.0-beta/cover-images.tar.xz
wget -nc https://github.com/nanmu42/orly/releases/download/1.1.0-beta/fonts.tar.xz
cd ..
make all

O'RLY consists of an API instance and a static frontend:

  • API source lies in cmd/rly;
  • Frontend source lies in frontend

Animal images and font files are in coverimage and font respectively.

More documentations can be found in their directory.

Contributes O'RLY

Contributions are always welcome!

Here are a few directions if you are interested:

  • Help translating the frontend(we are using Vue i18n)
  • Improve O'RLY
  • Add New Features
  • Raise a bug report

Or simply...

  • Sharing the fun 😉

Contributors

Many thanks 🤗 to following contributors:

Projects in Brotherhood

There are several projects which share the idea:

Paperwork

"O'RLY Cover Generator" is just a parody, and it has no concern with O'Reilly Media.

This work uses Source Han Serif and Source Han Sans from Adobe and Google, with participation from partner foundries Changzhou SinoType in China, Iwata Corporation in Japan, and Sandoll Communications in Korea.

This work uses TrueType version of Source Sans Pro from Adobe by Paul D. Hunt.

The animal(well, not all of them are animal) images are from the USF ClipArt ETC project.

Acknowledgements

The author would like to thank JetBrains for providing a JetBrains Open Source license for his open source developments.

License

Use of this work is governed by the MIT License.

You may find a license copy in project root.

Documentation

Overview

Package orly implements an parody book cover generator.

A living instance can be found at https://rly.nanmu.me/

Index

Constants

View Source
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
)
View Source
const (
	BottomRight = "BR"
	BottomLeft  = "BL"
	TopRight    = "TR"
	TopLeft     = "TL"
)

GuideText Position

Variables

This section is empty.

Functions

func LoadFont

func LoadFont(fileName string) (loaded *truetype.Font, err error)

LoadFont loads and parses font from file system

func LoadTIFFFromFolder

func LoadTIFFFromFolder(folderPath string) func(fileName string) (image.Image, error)

LoadTIFFFromFolder func factory

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.

func NewImageCache

func NewImageCache() *ImageCache

NewImageCache returns a empty image store

func (*ImageCache) Load

func (i *ImageCache) Load(key string) (img image.Image, found bool)

Load returns the image stored in the map for a key, or nil if no value is present.

The found result indicates whether value was found in the map.

func (*ImageCache) Store

func (i *ImageCache) Store(key string, img image.Image)

Store sets the image for a key.

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) Load

func (i *ImageProvider) Load(fileName string, size image.Rectangle) (img image.Image, err error)

Load get image of specific size from cache or file system

func (*ImageProvider) Miss

func (i *ImageProvider) Miss() uint64

Miss report the num of cache miss

Directories

Path Synopsis
cmd
rly
rly is an API for O'RLY cover generation
rly is an API for O'RLY cover generation

Jump to

Keyboard shortcuts

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