feat(thumb): support output webp thumbnails for vips generator (#2657)

pull/2693/head
Aaron Liu 2025-07-15 13:51:23 +08:00
parent e96b595622
commit 15762cb393
4 changed files with 6 additions and 7 deletions

2
assets

@ -1 +1 @@
Subproject commit e47a708f727bf5243512ddd6d9c6eabd5bf61751 Subproject commit a827cc60f232ed8fb95afa6d3d434ef1c41ed251

View File

@ -41,7 +41,7 @@ func (f *FfmpegGenerator) Generate(ctx context.Context, es entitysource.EntitySo
tempOutputPath := filepath.Join( tempOutputPath := filepath.Join(
util.DataPath(f.settings.TempPath(ctx)), util.DataPath(f.settings.TempPath(ctx)),
thumbTempFolder, thumbTempFolder,
fmt.Sprintf("thumb_%s.%s", uuid.Must(uuid.NewV4()).String(), f.settings.ThumbEncode(ctx).Format), fmt.Sprintf("thumb_%s.png", uuid.Must(uuid.NewV4()).String()),
) )
if err := util.CreatNestedFolder(filepath.Dir(tempOutputPath)); err != nil { if err := util.CreatNestedFolder(filepath.Dir(tempOutputPath)); err != nil {

View File

@ -69,10 +69,9 @@ func (l *LibreOfficeGenerator) Generate(ctx context.Context, es entitysource.Ent
} }
// Convert the document to an image // Convert the document to an image
encode := l.settings.ThumbEncode(ctx)
cmd := exec.CommandContext(ctx, l.settings.LibreOfficePath(ctx), "--headless", cmd := exec.CommandContext(ctx, l.settings.LibreOfficePath(ctx), "--headless",
"--nologo", "--nofirststartwizard", "--invisible", "--norestore", "--convert-to", "--nologo", "--nofirststartwizard", "--invisible", "--norestore", "--convert-to",
encode.Format, "--outdir", tempOutputPath, tempInputPath) "png", "--outdir", tempOutputPath, tempInputPath)
// Redirect IO // Redirect IO
var stdErr bytes.Buffer var stdErr bytes.Buffer
@ -86,7 +85,7 @@ func (l *LibreOfficeGenerator) Generate(ctx context.Context, es entitysource.Ent
return &Result{ return &Result{
Path: filepath.Join( Path: filepath.Join(
tempOutputPath, tempOutputPath,
strings.TrimSuffix(filepath.Base(tempInputPath), filepath.Ext(tempInputPath))+"."+encode.Format, strings.TrimSuffix(filepath.Base(tempInputPath), filepath.Ext(tempInputPath))+".png",
), ),
Continue: true, Continue: true,
Cleanup: []func(){func() { _ = os.RemoveAll(tempOutputPath) }}, Cleanup: []func(){func() { _ = os.RemoveAll(tempOutputPath) }},

View File

@ -38,8 +38,8 @@ func (v *VipsGenerator) Generate(ctx context.Context, es entitysource.EntitySour
outputOpt := ".png" outputOpt := ".png"
encode := v.settings.ThumbEncode(ctx) encode := v.settings.ThumbEncode(ctx)
if encode.Format == "jpg" { if encode.Format == "jpg" || encode.Format == "webp" {
outputOpt = fmt.Sprintf(".jpg[Q=%d]", encode.Quality) outputOpt = fmt.Sprintf(".%s[Q=%d]", encode.Format, encode.Quality)
} }
input := "[descriptor=0]" input := "[descriptor=0]"