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 // 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( 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{ []byte(e.render(epubtemplates.Blank, map[string]any{
"Title": fmt.Sprintf("Blank Page %d", img.Id), "Title": fmt.Sprintf("Blank Page %d", img.Id),
"ViewPort": fmt.Sprintf("width=%d,height=%d", e.Image.View.Width, e.Image.View.Height), "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() { go func() {
defer wg.Done() defer wg.Done()
for img := range imageInput { for input := range imageInput {
src := img.Image 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 var raw image.Image
if img.Id == 0 && part == 0 { if input.Id == 0 && part == 0 {
raw = dst raw = dst
} }
imageOutput <- &LoadedImage{ img := &epubimage.Image{
Image: &epubimage.Image{ Id: input.Id,
Id: img.Id,
Part: part, Part: part,
Raw: raw, Raw: raw,
Width: dst.Bounds().Dx(), Width: dst.Bounds().Dx(),
Height: dst.Bounds().Dy(), Height: dst.Bounds().Dy(),
IsCover: img.Id == 0 && part == 0, IsCover: input.Id == 0 && part == 0,
DoublePage: part == 0 && src.Bounds().Dx() > src.Bounds().Dy(), DoublePage: part == 0 && src.Bounds().Dx() > src.Bounds().Dy(),
Path: img.Path, Path: input.Path,
Name: img.Name, Name: input.Name,
}, }
ZipImage: epubzip.CompressImage(fmt.Sprintf("OEBPS/Images/%d_p%d.jpg", img.Id, part), dst, o.Image.Quality), imageOutput <- &LoadedImage{
Image: img,
ZipImage: epubzip.CompressImage(fmt.Sprintf("OEBPS/%s", img.ImgPath()), dst, o.Image.Quality),
} }
} }
} }