fixedlayout

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package fixedlayout writes a fixed-layout EPUB 3 from the pages of a CBZ: one XHTML page per image, each sized for e-reader screens. It is plain EPUB with no Kobo markup, so both the CBZ to EPUB and the CBZ to KePub Conversions write it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertCBZ

func ConvertCBZ(ctx context.Context, srcPath, destPath string, metadata *Metadata) error

ConvertCBZ converts the CBZ at srcPath to a fixed-layout EPUB at destPath. It is a path-based wrapper over PrepareCBZ and Conversion.Write; downloads call those directly through pkg/filegen. metadata may be nil.

Types

type Author

type Author struct {
	Name     string
	SortName string // e.g., "Doe, Jane" for sorting/file-as
	Role     string // writer, penciller, inker, etc.
}

Author represents an author/creator for CBZ metadata.

type Chapter

type Chapter struct {
	Title     string
	StartPage int // 0-indexed page number
}

Chapter represents a chapter/section for CBZ metadata.

type Conversion

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

Conversion is a CBZ ready to be converted to a fixed-layout EPUB.

func PrepareCBZ

func PrepareCBZ(srcZip *zip.Reader, metadata *Metadata) (*Conversion, error)

PrepareCBZ finds the pages of the CBZ in srcZip and checks that each can be opened, so a CBZ the conversion cannot use fails before anything is written. Pages are read only by Write, and srcZip must stay readable until it returns.

func (*Conversion) Write

func (cv *Conversion) Write(ctx context.Context, w io.Writer) error

Write writes the EPUB to w front to back. Each page's XHTML and image are written as soon as the page is processed, a bounded number of pages ahead, and the zip writer is flushed after each page so output arrives about once per page. The OPF, NCX, and nav list every page with its dimensions, so they come last; the container only requires mimetype first, and container.xml points to the OPF by path.

type Metadata

type Metadata struct {
	Title       string
	Subtitle    *string
	Description *string
	Authors     []Author
	Series      []Series
	Genres      []string
	Tags        []string
	URL         *string
	Publisher   *string
	ReleaseDate *time.Time
	Chapters    []Chapter
	CoverPage   *int    // 0-indexed page number for cover (nil = first page)
	Language    *string // BCP 47 language tag
}

Metadata is the book metadata written into the EPUB.

type ProcessedImage

type ProcessedImage struct {
	Data      []byte
	Width     int
	Height    int
	Ext       string
	MediaType string
}

ProcessedImage holds the result of image processing.

func ProcessImageForEreader

func ProcessImageForEreader(data []byte, origExt string) *ProcessedImage

ProcessImageForEreader resizes images to fit e-reader screen dimensions. - All JPEG/PNG images are resized to fit within Kobo Libra Color resolution (1264x1680) - PNG images are converted to JPEG for smaller file size - Other formats (GIF, WebP) are passed through unchanged.

Tones and colors are left alone: one generated file serves every reader, from e-ink to phones, so reducing grays or dropping color for a screen is left to the reading app. A page comes out gray only if it holds nothing but grays: it decoded as gray, or as a palette of grays.

pkg/filegen/cbz.go uses it too, so a change here also changes regular CBZ downloads.

type Series

type Series struct {
	Name   string
	Number *float64
}

Series represents series information for CBZ metadata.

Jump to

Keyboard shortcuts

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