mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-24 15:52:38 +02:00
move epubimageprocessor outside epub
This commit is contained in:
parent
55b8bbe6b3
commit
db58244946
@ -16,8 +16,8 @@ import (
|
||||
"time"
|
||||
|
||||
epubimage "github.com/celogeek/go-comic-converter/v2/pkg/epub/image"
|
||||
epubimageprocessor "github.com/celogeek/go-comic-converter/v2/pkg/epub/imageprocessor"
|
||||
epubtemplates "github.com/celogeek/go-comic-converter/v2/pkg/epub/templates"
|
||||
"github.com/celogeek/go-comic-converter/v2/pkg/epubimageprocessor"
|
||||
"github.com/celogeek/go-comic-converter/v2/pkg/epuboptions"
|
||||
"github.com/celogeek/go-comic-converter/v2/pkg/epubprogress"
|
||||
"github.com/celogeek/go-comic-converter/v2/pkg/epubtree"
|
||||
|
@ -6,7 +6,6 @@ package epubimageprocessor
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"os"
|
||||
"sync"
|
||||
@ -289,55 +288,3 @@ func (e *EPUBImageProcessor) transformImage(src image.Image, srcId int) []image.
|
||||
|
||||
return images
|
||||
}
|
||||
|
||||
type CoverTitleDataOptions struct {
|
||||
Src image.Image
|
||||
Name string
|
||||
Text string
|
||||
Align string
|
||||
PctWidth int
|
||||
PctMargin int
|
||||
MaxFontSize int
|
||||
BorderSize int
|
||||
}
|
||||
|
||||
func (e *EPUBImageProcessor) Cover16LevelOfGray(bounds image.Rectangle) draw.Image {
|
||||
return image.NewPaletted(bounds, color.Palette{
|
||||
color.Gray{0x00},
|
||||
color.Gray{0x11},
|
||||
color.Gray{0x22},
|
||||
color.Gray{0x33},
|
||||
color.Gray{0x44},
|
||||
color.Gray{0x55},
|
||||
color.Gray{0x66},
|
||||
color.Gray{0x77},
|
||||
color.Gray{0x88},
|
||||
color.Gray{0x99},
|
||||
color.Gray{0xAA},
|
||||
color.Gray{0xBB},
|
||||
color.Gray{0xCC},
|
||||
color.Gray{0xDD},
|
||||
color.Gray{0xEE},
|
||||
color.Gray{0xFF},
|
||||
})
|
||||
}
|
||||
|
||||
// create a title page with the cover
|
||||
func (e *EPUBImageProcessor) CoverTitleData(o *CoverTitleDataOptions) (*epubzip.EPUBZipImage, error) {
|
||||
// Create a blur version of the cover
|
||||
g := gift.New(epubimagefilters.CoverTitle(o.Text, o.Align, o.PctWidth, o.PctMargin, o.MaxFontSize, o.BorderSize))
|
||||
var dst draw.Image
|
||||
if o.Name == "cover" && e.Image.GrayScale {
|
||||
dst = e.Cover16LevelOfGray(o.Src.Bounds())
|
||||
} else {
|
||||
dst = e.createImage(o.Src, g.Bounds(o.Src.Bounds()))
|
||||
}
|
||||
g.Draw(dst, o.Src)
|
||||
|
||||
return epubzip.CompressImage(
|
||||
fmt.Sprintf("OEBPS/Images/%s.%s", o.Name, e.Image.Format),
|
||||
e.Image.Format,
|
||||
dst,
|
||||
e.Image.Quality,
|
||||
)
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package epubimageprocessor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
|
||||
epubimagefilters "github.com/celogeek/go-comic-converter/v2/pkg/epub/imagefilters"
|
||||
"github.com/celogeek/go-comic-converter/v2/pkg/epubzip"
|
||||
"github.com/disintegration/gift"
|
||||
)
|
||||
|
||||
type CoverTitleDataOptions struct {
|
||||
Src image.Image
|
||||
Name string
|
||||
Text string
|
||||
Align string
|
||||
PctWidth int
|
||||
PctMargin int
|
||||
MaxFontSize int
|
||||
BorderSize int
|
||||
}
|
||||
|
||||
// create a title page with the cover
|
||||
func (e *EPUBImageProcessor) CoverTitleData(o *CoverTitleDataOptions) (*epubzip.EPUBZipImage, error) {
|
||||
// Create a blur version of the cover
|
||||
g := gift.New(epubimagefilters.CoverTitle(o.Text, o.Align, o.PctWidth, o.PctMargin, o.MaxFontSize, o.BorderSize))
|
||||
var dst draw.Image
|
||||
if o.Name == "cover" && e.Image.GrayScale {
|
||||
// 16 shade of gray
|
||||
dst = image.NewPaletted(o.Src.Bounds(), color.Palette{
|
||||
color.Gray{0x00},
|
||||
color.Gray{0x11},
|
||||
color.Gray{0x22},
|
||||
color.Gray{0x33},
|
||||
color.Gray{0x44},
|
||||
color.Gray{0x55},
|
||||
color.Gray{0x66},
|
||||
color.Gray{0x77},
|
||||
color.Gray{0x88},
|
||||
color.Gray{0x99},
|
||||
color.Gray{0xAA},
|
||||
color.Gray{0xBB},
|
||||
color.Gray{0xCC},
|
||||
color.Gray{0xDD},
|
||||
color.Gray{0xEE},
|
||||
color.Gray{0xFF},
|
||||
})
|
||||
} else {
|
||||
dst = e.createImage(o.Src, g.Bounds(o.Src.Bounds()))
|
||||
}
|
||||
g.Draw(dst, o.Src)
|
||||
|
||||
return epubzip.CompressImage(
|
||||
fmt.Sprintf("OEBPS/Images/%s.%s", o.Name, e.Image.Format),
|
||||
e.Image.Format,
|
||||
dst,
|
||||
e.Image.Quality,
|
||||
)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user