use img helper

This commit is contained in:
Celogeek 2023-04-27 18:33:04 +02:00
parent 06cc6d2788
commit 12cd279bb8
Signed by: celogeek
SSH Key Fingerprint: SHA256:njNJLzoLQdbV9PC6ehcruRb0QnEgxABoCYZ+0+aUIYc
2 changed files with 18 additions and 17 deletions

View File

@ -87,7 +87,7 @@ func (e *ePub) writeImage(wz *epubzip.EpubZip, img *epubimageprocessing.LoadedIm
// write blank page
func (e *ePub) writeBlank(wz *epubzip.EpubZip, img *epubimage.Image) error {
return wz.WriteContent(
fmt.Sprintf("OEBPS/Text/%d_sp.xhtml", img.Id),
fmt.Sprintf("OEBPS/%s", img.SpacePath()),
[]byte(e.render(epubtemplates.Blank, map[string]any{
"Title": fmt.Sprintf("Blank Page %d", img.Id),
"ViewPort": fmt.Sprintf("width=%d,height=%d", e.Image.View.Width, e.Image.View.Height),

View File

@ -85,28 +85,29 @@ func LoadImages(o *epuboptions.Options) (LoadedImages, error) {
go func() {
defer wg.Done()
for img := range imageInput {
src := img.Image
for input := range imageInput {
src := input.Image
for part, dst := range TransformImage(src, img.Id, o.Image) {
for part, dst := range TransformImage(src, input.Id, o.Image) {
var raw image.Image
if img.Id == 0 && part == 0 {
if input.Id == 0 && part == 0 {
raw = dst
}
img := &epubimage.Image{
Id: input.Id,
Part: part,
Raw: raw,
Width: dst.Bounds().Dx(),
Height: dst.Bounds().Dy(),
IsCover: input.Id == 0 && part == 0,
DoublePage: part == 0 && src.Bounds().Dx() > src.Bounds().Dy(),
Path: input.Path,
Name: input.Name,
}
imageOutput <- &LoadedImage{
Image: &epubimage.Image{
Id: img.Id,
Part: part,
Raw: raw,
Width: dst.Bounds().Dx(),
Height: dst.Bounds().Dy(),
IsCover: img.Id == 0 && part == 0,
DoublePage: part == 0 && src.Bounds().Dx() > src.Bounds().Dy(),
Path: img.Path,
Name: img.Name,
},
ZipImage: epubzip.CompressImage(fmt.Sprintf("OEBPS/Images/%d_p%d.jpg", img.Id, part), dst, o.Image.Quality),
Image: img,
ZipImage: epubzip.CompressImage(fmt.Sprintf("OEBPS/%s", img.ImgPath()), dst, o.Image.Quality),
}
}
}