cbconvert

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: GPL-3.0 Imports: 35 Imported by: 2

README

CBconvert

Introduction

CBconvert is a Comic Book converter.

It can convert comics to different formats to fit your various devices.

screenshot

See more screenshots.

Features

  • reads CBR (RAR), CBZ (ZIP), CB7 (7Z), CBT (TAR), PDF, XPS, EPUB, MOBI, DOCX, PPTX and plain directory
  • saves processed files in ZIP archive format or TAR
  • images can be converted to JPEG, PNG, TIFF, WEBP, AVIF, JXL, or 4-Bit BMP (16 colors) image format
  • rotate, adjust brightness/contrast or grayscale images
  • resize filters (NearestNeighbor, Box, Linear, MitchellNetravali, CatmullRom, Gaussian, Lanczos)
  • export covers from comics
  • create thumbnails from covers by FreeDesktop specification

Download

Download the latest binaries from the releases.

Linux Flatpak is available at Flathub.

Using cbconvert in file managers to generate FreeDesktop thumbnails

Copy/install cbconvert cli binary to your PATH, create file ~/.local/share/thumbnailers/cbconvert.thumbnailer and paste contents from thumbnailer.

This is what it looks like in the PCManFM file manager:

thumbnails

Using command line app

    Usage: cbconvert <command> [<flags>] [file1 dir1 ... fileOrDirN]


    Commands:

      convert
            Convert archive or document

        --width
            Image width (default "0")
        --height
            Image height (default "0")
        --fit
            Best fit for required width and height (default "false")
        --format
            Image format, valid values are jpeg, png, tiff, bmp, webp, avif, jxl (default "jpeg")
        --archive
            Archive format, valid values are zip, tar (default "zip")
        --quality
            Image quality (default "75")
        --filter
            0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos (default "2")
        --no-cover
            Do not convert the cover image (default "false")
        --no-rgb
            Do not convert images that have RGB colorspace (default "false")
        --no-nonimage
            Remove non-image files from the archive (default "false")
        --no-convert
            Do not transform or convert images (default "false")
        --grayscale
            Convert images to grayscale (monochromatic) (default "false")
        --rotate
            Rotate images, valid values are 0, 90, 180, 270 (default "0")
        --brightness
            Adjust the brightness of the images, must be in the range (-100, 100) (default "0")
        --contrast
            Adjust the contrast of the images, must be in the range (-100, 100) (default "0")
        --suffix
            Add suffix to file basename (default "")
        --outdir
            Output directory (default ".")
        --size
            Process only files larger than size (in MB) (default "0")
        --recursive
            Process subdirectories recursively (default "false")
        --quiet
            Hide console output (default "false")

      cover
            Extract cover

        --width
            Image width (default "0")
        --height
            Image height (default "0")
        --fit
            Best fit for required width and height (default "false")
        --format
            Image format, valid values are jpeg, png, tiff, bmp, webp, avif, jxl (default "jpeg")
        --quality
            Image quality (default "75")
        --filter
            0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos (default "2")
        --outdir
            Output directory (default ".")
        --size
            Process only files larger than size (in MB) (default "0")
        --recursive
            Process subdirectories recursively (default "false")
        --quiet
            Hide console output (default "false")

      thumbnail
            Extract cover thumbnail (freedesktop spec.)

        --width
            Image width (default "0")
        --height
            Image height (default "0")
        --fit
            Best fit for required width and height (default "false")
        --filter
            0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos (default "2")
        --outdir
            Output directory (default ".")
        --outfile
            Output file (default "")
        --size
            Process only files larger than size (in MB) (default "0")
        --recursive
            Process subdirectories recursively (default "false")
        --quiet
            Hide console output (default "false")

      meta
            CBZ metadata

        --cover
            Print cover name (default "false")
        --comment
            Print zip comment (default "false")
        --comment-body
            Set zip comment (default "")
        --file-add
            Add file to archive (default "")
        --file-remove
            Remove file(s) from archive (glob pattern, i.e. *.xml) (default "")

Examples

  • Rescale images to 1200px for all supported files found in a directory with a size larger than 60MB:

cbconvert --recursive --width 1200 --size 60 /media/comics/Thorgal/

  • Convert all images in pdf to 4bit BMP images and save the result in ~/comics directory:

cbconvert --format bmp --outdir ~/comics /media/comics/Garfield/Garfield_01.pdf

BMP format is a very good choice for black&white pages. Archive size can be smaller 2-3x and the file will be readable by comic readers.

  • Extract covers to ~/covers dir for all supported files found in the directory, Lanczos algorithm is used for resizing:

cbconvert cover --outdir ~/covers --filter=7 /media/comics/GrooTheWanderer/

  • Convert all images to AVIF format:

cbconvert --format avif --quality 50 --width 1280 --outdir ~/comics /media/comics/Misc/

Quality settings

This table maps quality settings for JPEG to the respective AVIF and WEBP quality settings:

JPEG quality 50 60 70 80
AVIF quality 48 51 56 64
WEBP quality 55 64 72 82

Compile

You must have CGO_ENABLED=1. Note that Go will disable cgo when cross-compiling.

Install to GOBIN (you can point GOBIN to e.g. /usr/local/bin or ~/.local/bin):

go install github.com/gen2brain/cbconvert/cmd/cbconvert@latest

For GUI app, check IUP requirements, and then install:

go install github.com/gen2brain/cbconvert/cmd/cbconvert-gui@latest

Build tags

  • extlib - use external libmupdf and libunarr libraries
  • pkgconfig - enable pkg-config (used with extlib)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Converter added in v1.0.4

type Converter struct {
	// Options struct
	Opts Options
	// Current working directory
	Workdir string
	// Number of files
	Nfiles int
	// Index of current file
	CurrFile int
	// Number of contents in archive/document
	Ncontents int
	// Index of current content
	CurrContent int32
	// Start function
	OnStart func()
	// Progress function
	OnProgress func()
	// Compress function
	OnCompress func()
	// Cancel function
	OnCancel func()
}

Converter type.

func New

func New(o Options) *Converter

New returns new converter.

func (*Converter) Cancel added in v1.0.4

func (c *Converter) Cancel()

Cancel cancels the operation.

func (*Converter) Convert added in v1.0.4

func (c *Converter) Convert(fileName string, fileInfo os.FileInfo) error

Convert converts comic book.

func (*Converter) Cover added in v1.0.4

func (c *Converter) Cover(fileName string, fileInfo os.FileInfo) error

Cover extracts cover.

func (*Converter) Files added in v1.0.4

func (c *Converter) Files(args []string) ([]File, error)

Files returns list of found comic files.

func (*Converter) Meta added in v1.0.4

func (c *Converter) Meta(fileName string) (any, error)

Meta manipulates with CBZ metadata.

func (*Converter) Preview added in v1.0.4

func (c *Converter) Preview(fileName string, fileInfo os.FileInfo, width, height int) (Image, error)

Preview returns image preview.

func (*Converter) Thumbnail added in v1.0.4

func (c *Converter) Thumbnail(fileName string, fileInfo os.FileInfo) error

Thumbnail extracts thumbnail.

type File

type File struct {
	Name      string
	Path      string
	Stat      os.FileInfo
	SizeHuman string
}

File type.

type Image

type Image struct {
	Image     image.Image
	Width     int
	Height    int
	SizeHuman string
}

Image type.

type Options

type Options struct {
	// Image format, valid values are jpeg, png, tiff, bmp, webp, avif, jxl
	Format string
	// Archive format, valid values are zip, tar
	Archive string
	// JPEG image quality
	Quality int
	// Image width
	Width int
	// Image height
	Height int
	// Best fit for required width and height
	Fit bool
	// 0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos
	Filter int
	// Do not convert the cover image
	NoCover bool
	// Do not convert images that have RGB colorspace
	NoRGB bool
	// Remove non-image files from the archive
	NoNonImage bool
	// Do not transform or convert images
	NoConvert bool
	// Add suffix to file baseNoExt
	Suffix string
	// Extract cover
	Cover bool
	// Extract cover thumbnail (freedesktop spec.)
	Thumbnail bool
	// CBZ metadata
	Meta bool
	// Version
	Version bool
	// ZIP comment
	Comment bool
	// ZIP comment body
	CommentBody string
	// Add file
	FileAdd string
	// Remove file
	FileRemove string
	// Output file
	OutFile string
	// Output directory
	OutDir string
	// Convert images to grayscale (monochromatic)
	Grayscale bool
	// Rotate images, valid values are 0, 90, 180, 270
	Rotate int
	// Adjust the brightness of the images, must be in the range (-100, 100)
	Brightness int
	// Adjust the contrast of the images, must be in the range (-100, 100)
	Contrast int
	// Process subdirectories recursively
	Recursive bool
	// Process only files larger than size (in MB)
	Size int
	// Hide console output
	Quiet bool
}

Options type.

func NewOptions

func NewOptions() Options

NewOptions returns default options.

Directories

Path Synopsis
cmd
cbconvert module
cbconvert-gui module

Jump to

Keyboard shortcuts

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