mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-24 15:52:38 +02:00
add format copy option
This commit is contained in:
parent
673a7df699
commit
a5ef2a2927
@ -15,6 +15,7 @@ import (
|
||||
"reflect"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -131,7 +132,7 @@ func (c *Converter) InitParse() {
|
||||
c.AddStringParam(&c.Options.Image.View.Color.Foreground, "foreground-color", c.Options.Image.View.Color.Foreground, "Foreground color in hexadecimal format RGB. Black=000, White=FFF")
|
||||
c.AddStringParam(&c.Options.Image.View.Color.Background, "background-color", c.Options.Image.View.Color.Background, "Background color in hexadecimal format RGB. Black=000, White=FFF, Light Gray=DDD, Dark Gray=777")
|
||||
c.AddBoolParam(&c.Options.Image.Resize, "resize", c.Options.Image.Resize, "Reduce image size if exceed device size")
|
||||
c.AddStringParam(&c.Options.Image.Format, "format", c.Options.Image.Format, "Format of output images: jpeg (lossy), png (lossless)")
|
||||
c.AddStringParam(&c.Options.Image.Format, "format", c.Options.Image.Format, "Format of output images: jpeg (lossy), png (lossless), copy (no processing)")
|
||||
c.AddFloatParam(&c.Options.Image.View.AspectRatio, "aspect-ratio", c.Options.Image.View.AspectRatio, "Aspect ratio (height/width) of the output\n -1 = same as device\n 0 = same as source\n1.6 = amazon advice for kindle")
|
||||
c.AddBoolParam(&c.Options.Image.View.PortraitOnly, "portrait-only", c.Options.Image.View.PortraitOnly, "Portrait only: force orientation to portrait only.")
|
||||
c.AddIntParam(&c.Options.TitlePage, "titlepage", c.Options.TitlePage, "Title page\n0 = never\n1 = always\n2 = only if epub is split")
|
||||
@ -379,8 +380,8 @@ func (c *Converter) Validate() error {
|
||||
}
|
||||
|
||||
// Format
|
||||
if !(c.Options.Image.Format == "jpeg" || c.Options.Image.Format == "png") {
|
||||
return errors.New("format should be jpeg or png")
|
||||
if !slices.Contains([]string{"jpeg", "png", "copy"}, c.Options.Image.Format) {
|
||||
return errors.New("format should be jpeg, png or copy")
|
||||
}
|
||||
|
||||
// Aspect Ratio
|
||||
|
@ -53,7 +53,7 @@ func (e EPUBImageProcessor) isSupportedImage(path string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Load images from input
|
||||
// load images from input
|
||||
func (e EPUBImageProcessor) load() (totalImages int, output chan task, err error) {
|
||||
fi, err := os.Stat(e.Input)
|
||||
if err != nil {
|
||||
|
8
internal/pkg/epubimageprocessor/passthrough.go
Normal file
8
internal/pkg/epubimageprocessor/passthrough.go
Normal file
@ -0,0 +1,8 @@
|
||||
package epubimageprocessor
|
||||
|
||||
import "github.com/celogeek/go-comic-converter/v3/internal/pkg/epubimage"
|
||||
|
||||
func (e EPUBImageProcessor) PassThrough() (images []epubimage.EPUBImage, err error) {
|
||||
images = make([]epubimage.EPUBImage, 0)
|
||||
return images, nil
|
||||
}
|
@ -3,6 +3,7 @@ package epub
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"path/filepath"
|
||||
@ -202,12 +203,23 @@ func (e epub) writeTitleImage(wz epubzip.EPUBZip, img epubimage.EPUBImage, title
|
||||
|
||||
// extract image and split it into part
|
||||
func (e epub) getParts() (parts []epubPart, imgStorage epubzip.StorageImageReader, err error) {
|
||||
images, err := e.imageProcessor.Load()
|
||||
images, err := func() ([]epubimage.EPUBImage, error) {
|
||||
if e.EPUBOptions.Image.Format == "copy" {
|
||||
return e.imageProcessor.PassThrough()
|
||||
} else {
|
||||
return e.imageProcessor.Load()
|
||||
}
|
||||
}()
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if len(images) == 0 {
|
||||
err = errors.New("no image found")
|
||||
return
|
||||
}
|
||||
|
||||
// sort result by id and part
|
||||
sort.Slice(images, func(i, j int) bool {
|
||||
if images[i].Id == images[j].Id {
|
||||
|
Loading…
x
Reference in New Issue
Block a user