Compare commits

..

2 Commits

Author SHA1 Message Date
b71deb257a
change Epub, epub to EPUB in code and comment 2023-04-29 11:55:13 +02:00
8cf02445e7
update readme 2023-04-29 11:54:32 +02:00
9 changed files with 148 additions and 69 deletions

125
README.md
View File

@ -1,10 +1,31 @@
# go-comic-converter
Convert CBZ/CBR/Dir into Epub for e-reader devices (Kindle Devices, ...)
Convert CBZ/CBR/Dir into EPUB for e-reader devices (Kindle Devices, ...)
My goal is to make a simple, crossplatform, and fast tool to convert comics into epub.
My goal is to make a simple, crossplatform, and fast tool to convert comics into EPUB.
Epub is now support by Amazon through [SendToKindle](https://www.amazon.com/gp/sendtokindle/), by Email or by using the App. So I've made it simple to support the size limit constraint of those services.
EPUB is now support by Amazon through [SendToKindle](https://www.amazon.com/gp/sendtokindle/), by Email or by using the App. So I've made it simple to support the size limit constraint of those services.
# Features
- Support input from zip, cbz, rar, cbr, pdf, directory
- Support all Kindle devices and kobo
- Support Landscape and Portrait mode
- Customize output image quality
- Intelligent cropping (support removing even page numbers)
- Customize brightness and contrast
- Auto rotate (if reader mainly read on portrait)
- Auto split double page (for easy read on portrait)
- Remove blank image (empty image is removed)
- Manga or Normal mode
- Support cover page or not (first page will be taken in that case)
- Split EPUB size for easy upload
- 3 sorting methods (depending on your source, you can ensure the page go in the right order)
- Save and reuse your own perfect settings
- Multi tasks for fast conversion
When you read the comic on a Kindle, you can customize how you read it with the `Aa` button:
- Landscape / Portrait
- Activate panel view for small device
# Installation
@ -37,19 +58,19 @@ You can check if a new version is available with:
$ go-comic-converter -version
go-comic-converter
Path : github.com/celogeek/go-comic-converter/v2
Sum : h1:k1lhD90H0Cpno4VDFAR8OZYrnfV3SqUdVbYL+El9ZA4=
Version : v2.0.6
Available Version: v2.0.6
Sum : h1:9xYksu1PlJ6QkAL/5U2ZbufEb1tavpdRcpTPPcAjiNs=
Version : v2.3.3
Available Version: v2.3.3
To install the latest version:
$ go install github.com/celogeek/go-comic-converter/v2@v2.0.6
$ go install github.com/celogeek/go-comic-converter/v2@v2.3.3
```
# Supported image files
The supported image files are jpeg and png from the sources.
The extensions can be: `jpg`, `jpeg`, `png`.
The extensions can be: `jpg`, `jpeg`, `png`, `webp`.
The case for extensions doesn't matter.
@ -97,7 +118,7 @@ The ePub include as a first page:
- Title
- Part NUM / TOTAL
If the total is above 1, then the title of the epub include:
If the total is above 1, then the title of the EPUB include:
- Title [part/total]
## Dry run
@ -119,11 +140,12 @@ Options:
View : 1653x2480
Quality : 85
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
Brightness : 0
Contrast : 0
AutoRotate : true
AutoSplitDoublePage : true
NoBlankPage : false
NoBlankImage : true
Manga : true
HasCover : true
LimitMb : 200 Mb
@ -158,11 +180,12 @@ Options:
View : 1653x2480
Quality : 85
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
Brightness : 0
Contrast : 0
AutoRotate : true
AutoSplitDoublePage : true
NoBlankPage : false
NoBlankImage : true
Manga : true
HasCover : true
LimitMb : 200 Mb
@ -203,13 +226,16 @@ Go Comic Converter
Options:
Profile :
ViewRatio : 1:1.5
View :
Quality : 85
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
Brightness : 0
Contrast : 0
AutoRotate : false
AutoSplitDoublePage : false
NoBlankPage : false
NoBlankImage : true
Manga : false
HasCover : true
LimitMb : nolimit
@ -229,18 +255,19 @@ Options:
View : 1653x2480
Quality : 85
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
Brightness : 0
Contrast : 0
AutoRotate : true
AutoSplitDoublePage : true
NoBlankPage : false
NoBlankImage : true
Manga : true
HasCover : true
LimitMb : 200 Mb
StripFirstDirectoryFromToc: false
SortPathMode : path=alphanum, file=alpha
Saving to /Users/vincent/.go-comic-converter.yaml
Saving to ~/.go-comic-converter.yaml
```
If you want to change a setting, you can change only one of them
@ -255,18 +282,19 @@ Options:
View : 1653x2480
Quality : 85
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
Brightness : 0
Contrast : 0
AutoRotate : true
AutoSplitDoublePage : true
NoBlankPage : false
NoBlankImage : true
Manga : false
HasCover : true
LimitMb : 200 Mb
StripFirstDirectoryFromToc: false
SortPathMode : path=alphanum, file=alpha
Saving to /Users/vincent/.go-comic-converter.yaml
Saving to ~/.go-comic-converter.yaml
```
### Reset default
@ -278,20 +306,63 @@ Go Comic Converter
Options:
Profile :
ViewRatio : 1:1.5
View :
Quality : 85
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
Brightness : 0
Contrast : 0
AutoRotate : false
AutoSplitDoublePage: false
NoBlankPage : false
AutoSplitDoublePage : false
NoBlankImage : true
Manga : false
HasCover : true
LimitMb : nolimit
StripFirstDirectoryFromToc: false
SortPathMode : path=alphanum, file=alpha
Reset default to ~/.go-comic-converter.yaml
```
# My own settings
After playing around with the options, I have my perfect settings for a Kindle Scribe.
```
$ go-comic-converter -reset
$ go-comic-converter -profile KS -quality 90 -autosplitdoublepage -manga -limitmb 200 -strip -save
Go Comic Converter
Options:
Profile : KS - Kindle Scribe - 1860x2480
ViewRatio : 1:1.5
View : 1653x2480
Quality : 90
Crop : true
CropRatio : 1 Left - 1 Up - 1 Right - 3 Bottom
Brightness : 0
Contrast : 0
AutoRotate : false
AutoSplitDoublePage : true
NoBlankImage : true
Manga : true
HasCover : true
LimitMb : 200 Mb
StripFirstDirectoryFromToc: true
SortPathMode : path=alphanum, file=alpha
Saving to ~/.go-comic-converter.yaml
```
Explanation:
- `-profile KS`: Kindle Scribe
- `-quality 90`: JPEG output quality of images
- `-autosplitdoublepage`: split double page into 2 images after displaying in full quality. Perfect render in landscape, great in portrait
- `-manga`: manga mode, read right to left
- `-limitmb 200`: size limit to 200MB allowing upload from SendToKindle website
- `-strip`: remove first level if alone on TOC, as offen comics include a main directory with the title
# Help
```
@ -303,11 +374,11 @@ Output:
-input string
Source of comic to convert: directory, cbz, zip, cbr, rar, pdf
-output string
Output of the epub (directory or epub): (default [INPUT].epub)
Output of the EPUB (directory or EPUB): (default [INPUT].epub)
-author string (default "GO Comic Converter")
Author of the epub
Author of the EPUB
-title string
Title of the epub
Title of the EPUB
Config:
-profile string
@ -340,6 +411,14 @@ Config:
Quality of the image
-crop (default true)
Crop images
-crop-ratio-left int (default 1)
Crop ratio left: ratio of pixels allow to be non blank while cutting on the left.
-crop-ratio-up int (default 1)
Crop ratio up: ratio of pixels allow to be non blank while cutting on the top.
-crop-ratio-right int (default 1)
Crop ratio right: ratio of pixels allow to be non blank while cutting on the right.
-crop-ratio-bottom int (default 3)
Crop ratio bottom: ratio of pixels allow to be non blank while cutting on the bottom.
-brightness int
Brightness readjustement: between -100 and 100, > 0 lighter, < 0 darker
-contrast int
@ -350,8 +429,8 @@ Config:
Activate all automatic options
-autosplitdoublepage
Auto Split double page when width > height
-noblankpage
Remove blank pages
-noblankimage (default true)
Remove blank image
-manga
Manga mode (right to left)
-hascover (default true)

View File

@ -90,9 +90,9 @@ func (c *Converter) AddBoolParam(p *bool, name string, value bool, usage string)
func (c *Converter) InitParse() {
c.AddSection("Output")
c.AddStringParam(&c.Options.Input, "input", "", "Source of comic to convert: directory, cbz, zip, cbr, rar, pdf")
c.AddStringParam(&c.Options.Output, "output", "", "Output of the epub (directory or epub): (default [INPUT].epub)")
c.AddStringParam(&c.Options.Author, "author", "GO Comic Converter", "Author of the epub")
c.AddStringParam(&c.Options.Title, "title", "", "Title of the epub")
c.AddStringParam(&c.Options.Output, "output", "", "Output of the EPUB (directory or EPUB): (default [INPUT].epub)")
c.AddStringParam(&c.Options.Author, "author", "GO Comic Converter", "Author of the EPUB")
c.AddStringParam(&c.Options.Title, "title", "", "Title of the EPUB")
c.AddSection("Config")
c.AddStringParam(&c.Options.Profile, "profile", c.Options.Profile, fmt.Sprintf("Profile to use: \n%s", c.Options.AvailableProfiles()))
@ -110,7 +110,7 @@ func (c *Converter) InitParse() {
c.AddBoolParam(&c.Options.NoBlankImage, "noblankimage", c.Options.NoBlankImage, "Remove blank image")
c.AddBoolParam(&c.Options.Manga, "manga", c.Options.Manga, "Manga mode (right to left)")
c.AddBoolParam(&c.Options.HasCover, "hascover", c.Options.HasCover, "Has cover. Indicate if your comic have a cover. The first page will be used as a cover and include after the title.")
c.AddIntParam(&c.Options.LimitMb, "limitmb", c.Options.LimitMb, "Limit size of the ePub: Default nolimit (0), Minimum 20")
c.AddIntParam(&c.Options.LimitMb, "limitmb", c.Options.LimitMb, "Limit size of the EPUB: Default nolimit (0), Minimum 20")
c.AddBoolParam(&c.Options.StripFirstDirectoryFromToc, "strip", c.Options.StripFirstDirectoryFromToc, "Strip first directory from the TOC if only 1")
c.AddIntParam(&c.Options.SortPathMode, "sort", c.Options.SortPathMode, "Sort path mode\n0 = alpha for path and file\n1 = alphanum for path and alpha for file\n2 = alphanum for path and file")

View File

@ -1,5 +1,5 @@
/*
Tools to create epub from images.
Tools to create EPUB from images.
*/
package epub
@ -30,7 +30,7 @@ type ePub struct {
UpdatedAt string
templateProcessor *template.Template
imageProcessor *epubimageprocessor.EpubImageProcessor
imageProcessor *epubimageprocessor.EPUBImageProcessor
}
type epubPart struct {
@ -38,7 +38,7 @@ type epubPart struct {
LoadedImages epubimageprocessor.LoadedImages
}
// initialize epub
// initialize EPUB
func New(options *epuboptions.Options) *ePub {
uid := uuid.Must(uuid.NewV4())
tmpl := template.New("parser")
@ -68,7 +68,7 @@ func (e *ePub) render(templateString string, data map[string]any) string {
}
// write image to the zip
func (e *ePub) writeImage(wz *epubzip.EpubZip, img *epubimageprocessor.LoadedImage) error {
func (e *ePub) writeImage(wz *epubzip.EPUBZip, img *epubimageprocessor.LoadedImage) error {
err := wz.WriteContent(
fmt.Sprintf("OEBPS/%s", img.Image.PagePath()),
[]byte(e.render(epubtemplates.Text, map[string]any{
@ -87,7 +87,7 @@ func (e *ePub) writeImage(wz *epubzip.EpubZip, img *epubimageprocessor.LoadedIma
}
// write blank page
func (e *ePub) writeBlank(wz *epubzip.EpubZip, img *epubimage.Image) error {
func (e *ePub) writeBlank(wz *epubzip.EPUBZip, img *epubimage.Image) error {
return wz.WriteContent(
fmt.Sprintf("OEBPS/%s", img.SpacePath()),
[]byte(e.render(epubtemplates.Blank, map[string]any{
@ -127,7 +127,7 @@ func (e *ePub) getParts() ([]*epubPart, error) {
return parts, nil
}
// compute size of the epub part and try to be as close as possible of the target
// compute size of the EPUB part and try to be as close as possible of the target
maxSize := uint64(e.LimitMb * 1024 * 1024)
xhtmlSize := uint64(1024)
// descriptor files + title

View File

@ -31,16 +31,16 @@ func (l LoadedImages) Images() []*epubimage.Image {
return res
}
type EpubImageProcessor struct {
type EPUBImageProcessor struct {
*epuboptions.Options
}
func New(o *epuboptions.Options) *EpubImageProcessor {
return &EpubImageProcessor{o}
func New(o *epuboptions.Options) *EPUBImageProcessor {
return &EPUBImageProcessor{o}
}
// extract and convert images
func (e *EpubImageProcessor) Load() (LoadedImages, error) {
func (e *EPUBImageProcessor) Load() (LoadedImages, error) {
images := make(LoadedImages, 0)
imageCount, imageInput, err := e.load()
@ -135,7 +135,7 @@ func (e *EpubImageProcessor) Load() (LoadedImages, error) {
// transform image into 1 or 3 images
// only doublepage with autosplit has 3 versions
func (e *EpubImageProcessor) transformImage(src image.Image, srcId int) []image.Image {
func (e *EPUBImageProcessor) transformImage(src image.Image, srcId int) []image.Image {
var filters, splitFilter []gift.Filter
var images []image.Image
@ -220,7 +220,7 @@ func (e *EpubImageProcessor) transformImage(src image.Image, srcId int) []image.
}
// create a title page with the cover
func (e *EpubImageProcessor) CoverTitleData(img image.Image, title string) *epubzip.ZipImage {
func (e *EPUBImageProcessor) CoverTitleData(img image.Image, title string) *epubzip.ZipImage {
// Create a blur version of the cover
g := gift.New(epubimagefilters.CoverTitle(title))
dst := image.NewGray(g.Bounds(img.Bounds()))

View File

@ -34,7 +34,7 @@ type tasks struct {
var errNoImagesFound = errors.New("no images found")
// only accept jpg, png and webp as source file
func (e *EpubImageProcessor) isSupportedImage(path string) bool {
func (e *EPUBImageProcessor) isSupportedImage(path string) bool {
switch strings.ToLower(filepath.Ext(path)) {
case ".jpg", ".jpeg", ".png", ".webp":
{
@ -45,7 +45,7 @@ func (e *EpubImageProcessor) isSupportedImage(path string) bool {
}
// Load images from input
func (e *EpubImageProcessor) load() (totalImages int, output chan *tasks, err error) {
func (e *EPUBImageProcessor) load() (totalImages int, output chan *tasks, err error) {
fi, err := os.Stat(e.Input)
if err != nil {
return
@ -70,7 +70,7 @@ func (e *EpubImageProcessor) load() (totalImages int, output chan *tasks, err er
}
// load a directory of images
func (e *EpubImageProcessor) loadDir() (totalImages int, output chan *tasks, err error) {
func (e *EPUBImageProcessor) loadDir() (totalImages int, output chan *tasks, err error) {
images := make([]string, 0)
input := filepath.Clean(e.Input)
@ -160,7 +160,7 @@ func (e *EpubImageProcessor) loadDir() (totalImages int, output chan *tasks, err
}
// load a zip file that include images
func (e *EpubImageProcessor) loadCbz() (totalImages int, output chan *tasks, err error) {
func (e *EPUBImageProcessor) loadCbz() (totalImages int, output chan *tasks, err error) {
r, err := zip.OpenReader(e.Input)
if err != nil {
return
@ -246,7 +246,7 @@ func (e *EpubImageProcessor) loadCbz() (totalImages int, output chan *tasks, err
}
// load a rar file that include images
func (e *EpubImageProcessor) loadCbr() (totalImages int, output chan *tasks, err error) {
func (e *EPUBImageProcessor) loadCbr() (totalImages int, output chan *tasks, err error) {
var isSolid bool
files, err := rardecode.List(e.Input)
if err != nil {
@ -363,7 +363,7 @@ func (e *EpubImageProcessor) loadCbr() (totalImages int, output chan *tasks, err
}
// extract image from a pdf
func (e *EpubImageProcessor) loadPdf() (totalImages int, output chan *tasks, err error) {
func (e *EPUBImageProcessor) loadPdf() (totalImages int, output chan *tasks, err error) {
pdf := pdfread.Load(e.Input)
if pdf == nil {
err = fmt.Errorf("can't read pdf")

View File

@ -1,5 +1,5 @@
/*
Options for epub creation.
Options for EPUB creation.
*/
package epuboptions

View File

@ -1,5 +1,5 @@
/*
Templates use to create xml files of the epub.
Templates use to create xml files of the EPUB.
*/
package epubtemplates

View File

@ -1,7 +1,7 @@
/*
Helper to write epub files.
Helper to write EPUB files.
We create a zip with the magic epub mimetype.
We create a zip with the magic EPUB mimetype.
*/
package epubzip
@ -11,23 +11,23 @@ import (
"time"
)
type EpubZip struct {
type EPUBZip struct {
w *os.File
wz *zip.Writer
}
// create a new epub
func New(path string) (*EpubZip, error) {
// create a new EPUB
func New(path string) (*EPUBZip, error) {
w, err := os.Create(path)
if err != nil {
return nil, err
}
wz := zip.NewWriter(w)
return &EpubZip{w, wz}, nil
return &EPUBZip{w, wz}, nil
}
// close compress pipe and file.
func (e *EpubZip) Close() error {
func (e *EPUBZip) Close() error {
if err := e.wz.Close(); err != nil {
return err
}
@ -36,7 +36,7 @@ func (e *EpubZip) Close() error {
// Write mimetype, in a very specific way.
// This will be valid with epubcheck tools.
func (e *EpubZip) WriteMagic() error {
func (e *EPUBZip) WriteMagic() error {
t := time.Now()
fh := &zip.FileHeader{
Name: "mimetype",
@ -59,7 +59,7 @@ func (e *EpubZip) WriteMagic() error {
}
// Write image. They are already compressed, so we write them down directly.
func (e *EpubZip) WriteRaw(raw *ZipImage) error {
func (e *EPUBZip) WriteRaw(raw *ZipImage) error {
m, err := e.wz.CreateRaw(raw.Header)
if err != nil {
return err
@ -69,7 +69,7 @@ func (e *EpubZip) WriteRaw(raw *ZipImage) error {
}
// Write file. Compressed it using deflate.
func (e *EpubZip) WriteContent(file string, content []byte) error {
func (e *EPUBZip) WriteContent(file string, content []byte) error {
m, err := e.wz.CreateHeader(&zip.FileHeader{
Name: file,
Modified: time.Now(),

View File

@ -1,9 +1,9 @@
/*
Convert CBZ/CBR/Dir into Epub for e-reader devices (Kindle Devices, ...)
Convert CBZ/CBR/Dir into EPUB for e-reader devices (Kindle Devices, ...)
My goal is to make a simple, crossplatform, and fast tool to convert comics into epub.
My goal is to make a simple, crossplatform, and fast tool to convert comics into EPUB.
Epub is now support by Amazon through [SendToKindle](https://www.amazon.com/gp/sendtokindle/), by Email or by using the App. So I've made it simple to support the size limit constraint of those services.
EPUB is now support by Amazon through [SendToKindle](https://www.amazon.com/gp/sendtokindle/), by Email or by using the App. So I've made it simple to support the size limit constraint of those services.
*/
package main