cbconvert

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: GPL-3.0 Imports: 30 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 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, adjust levels (Photoshop-like) or grayscale images
  • resize filters (NearestNeighbor, Box, Linear, MitchellNetravali, CatmullRom, Gaussian, Lanczos)
  • export covers from comics
  • create thumbnails from covers by FreeDesktop specification

Download

flathub

Using cbconvert in file managers to generate FreeDesktop thumbnails

Copy cbconvert cli binary to your PATH and create file ~/.local/share/thumbnailers/cbconvert.thumbnailer:

[Thumbnailer Entry]
TryExec=cbconvert
Exec=cbconvert thumbnail --quiet --width %s --outfile %o %i
MimeType=application/pdf;application/x-cb7;application/x-cbt;application/epub+zip;application/vnd.comicbook-rar;application/vnd.comicbook+zip;application/x-mobipocket-ebook;application/vnd.ms-xpsdocument;

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 "")
        --levels-inmin
            Shadow input value (default "0")
        --levels-gamma
            Midpoint/Gamma (default "1")
        --levels-inmax
            Highlight input value (default "255")
        --levels-outmin
            Shadow output value (default "0")
        --levels-outmax
            Highlight output value (default "255")
        --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

Install ImageMagick7 (with libheif/libjxl support) and MuPDF libraries and headers and then install to GOBIN:

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

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

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

Documentation

Index

Constants

View Source
const (
	// NearestNeighbor is the fastest resampling filter, no antialiasing.
	NearestNeighbor int = iota
	// Box filter (averaging pixels).
	Box
	// Linear is the bilinear filter, smooth and reasonably fast.
	Linear
	// MitchellNetravali is a smooth bicubic filter.
	MitchellNetravali
	// CatmullRom is a sharp bicubic filter.
	CatmullRom
	// Gaussian is a blurring filter that uses gaussian function, useful for noise removal.
	Gaussian
	// Lanczos is a high-quality resampling filter, it's slower than cubic filters.
	Lanczos
)

Resample filters.

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) Initialize added in v1.0.4

func (c *Converter) Initialize()

Initialize inits ImageMagick.

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) Terminate added in v1.0.4

func (c *Converter) Terminate()

Terminate terminates ImageMagick.

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
	// Shadow input value
	LevelsInMin int
	// Highlight input value
	LevelsInMax int
	// Midpoint/gamma
	LevelsGamma float64
	// Shadow output value
	LevelsOutMin int
	// Highlight output value
	LevelsOutMax int
}

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