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(
util.DataPath(f.settings.TempPath(ctx)),
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 {

View File

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

View File

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