mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-24 15:52:38 +02:00
passthrough, add png support for dir reading
This commit is contained in:
parent
ad614d09b4
commit
af261d3f75
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
@ -56,7 +57,7 @@ func (e EPUBImageProcessor) passThroughDir() (images []epubimage.EPUBImage, err
|
||||
return nil
|
||||
}
|
||||
|
||||
if slices.Contains([]string{".jpeg", ".jpg"}, strings.ToLower(filepath.Ext(path))) {
|
||||
if slices.Contains([]string{".jpeg", ".jpg", ".png"}, strings.ToLower(filepath.Ext(path))) {
|
||||
imagesPath = append(imagesPath, path)
|
||||
}
|
||||
return nil
|
||||
@ -105,27 +106,44 @@ func (e EPUBImageProcessor) passThroughDir() (images []epubimage.EPUBImage, err
|
||||
return
|
||||
}
|
||||
|
||||
p, fn := filepath.Split(imgPath)
|
||||
if p == input {
|
||||
p = ""
|
||||
} else {
|
||||
p = p[len(input)+1:]
|
||||
}
|
||||
|
||||
var (
|
||||
format string
|
||||
decodeConfig func(r io.Reader) (image.Config, error)
|
||||
decode func(r io.Reader) (image.Image, error)
|
||||
)
|
||||
|
||||
switch filepath.Ext(fn) {
|
||||
case ".png":
|
||||
format = "png"
|
||||
decodeConfig = png.DecodeConfig
|
||||
decode = png.Decode
|
||||
case ".jpg", ".jpeg":
|
||||
format = "jpeg"
|
||||
decodeConfig = jpeg.DecodeConfig
|
||||
decode = jpeg.Decode
|
||||
}
|
||||
|
||||
var config image.Config
|
||||
config, err = jpeg.DecodeConfig(bytes.NewReader(uncompressedData))
|
||||
config, err = decodeConfig(bytes.NewReader(uncompressedData))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var rawImage image.Image
|
||||
if i == 0 {
|
||||
rawImage, err = jpeg.Decode(bytes.NewReader(uncompressedData))
|
||||
rawImage, err = decode(bytes.NewReader(uncompressedData))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
p, fn := filepath.Split(imgPath)
|
||||
if p == input {
|
||||
p = ""
|
||||
} else {
|
||||
p = p[len(input)+1:]
|
||||
}
|
||||
|
||||
img := epubimage.EPUBImage{
|
||||
Id: i,
|
||||
Part: 0,
|
||||
@ -136,7 +154,7 @@ func (e EPUBImageProcessor) passThroughDir() (images []epubimage.EPUBImage, err
|
||||
DoublePage: config.Width > config.Height,
|
||||
Path: p,
|
||||
Name: fn,
|
||||
Format: "jpeg",
|
||||
Format: format,
|
||||
OriginalAspectRatio: float64(config.Height) / float64(config.Width),
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user