diff --git a/pkg/epub/epub.go b/pkg/epub/epub.go index cea3169..0926197 100644 --- a/pkg/epub/epub.go +++ b/pkg/epub/epub.go @@ -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" diff --git a/pkg/epub/imageprocessor/imageprocessor.go b/pkg/epubimageprocessor/epubimageprocessor.go similarity index 84% rename from pkg/epub/imageprocessor/imageprocessor.go rename to pkg/epubimageprocessor/epubimageprocessor.go index 3e0c86e..ab02c6d 100644 --- a/pkg/epub/imageprocessor/imageprocessor.go +++ b/pkg/epubimageprocessor/epubimageprocessor.go @@ -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, - ) -} diff --git a/pkg/epubimageprocessor/epubimageprocessor_covert_title_data.go b/pkg/epubimageprocessor/epubimageprocessor_covert_title_data.go new file mode 100644 index 0000000..2c09cef --- /dev/null +++ b/pkg/epubimageprocessor/epubimageprocessor_covert_title_data.go @@ -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, + ) +} diff --git a/pkg/epub/imageprocessor/imageprocessor_loader.go b/pkg/epubimageprocessor/epubimageprocessor_loader.go similarity index 100% rename from pkg/epub/imageprocessor/imageprocessor_loader.go rename to pkg/epubimageprocessor/epubimageprocessor_loader.go