2 Commits

Author SHA1 Message Date
Antoine Aflalo
9ecd5ff3a5 fix(webp): fix the actual maximum limit 2024-08-28 11:53:26 -04:00
Antoine Aflalo
a63d2395f0 fix(webp): better handling of error for page too big for webp 2024-08-28 11:51:06 -04:00
2 changed files with 11 additions and 1 deletions

View File

@@ -21,6 +21,11 @@ func TestConvertChapter(t *testing.T) {
genTestChapter: genBigPages, genTestChapter: genBigPages,
split: true, split: true,
}, },
{
name: "Big Pages, no split",
genTestChapter: genBigPages,
split: false,
},
{ {
name: "No split pages", name: "No split pages",
genTestChapter: genSmallPages, genTestChapter: genSmallPages,
@@ -87,7 +92,7 @@ func genBigPages(path string) (*manga.Chapter, error) {
var pages []*manga.Page var pages []*manga.Page
for i := 0; i < 5; i++ { // Assuming there are 5 pages for the test for i := 0; i < 5; i++ { // Assuming there are 5 pages for the test
img := image.NewRGBA(image.Rect(0, 0, 300, 10000)) img := image.NewRGBA(image.Rect(0, 0, 300, 17000))
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
err := jpeg.Encode(buf, img, nil) err := jpeg.Encode(buf, img, nil)
if err != nil { if err != nil {

View File

@@ -17,6 +17,8 @@ import (
"sync/atomic" "sync/atomic"
) )
const webpMaxHeight = 16383
type Converter struct { type Converter struct {
maxHeight int maxHeight int
cropHeight int cropHeight int
@@ -202,6 +204,9 @@ func (converter *Converter) checkPageNeedsSplit(page *manga.Page) (bool, image.I
bounds := img.Bounds() bounds := img.Bounds()
height := bounds.Dy() height := bounds.Dy()
if height >= webpMaxHeight {
return false, img, format, fmt.Errorf("page[%d] height %d exceeds maximum height %d of webp format", page.Index, height, webpMaxHeight)
}
return height >= converter.maxHeight, img, format, nil return height >= converter.maxHeight, img, format, nil
} }