1
0
mirror of https://github.com/coalaura/ffwebp.git synced 2025-09-08 05:49:54 +00:00
This commit is contained in:
2025-08-11 04:03:19 +02:00
parent 3114d7f8c3
commit 86cc9e33de
6 changed files with 97 additions and 1 deletions

8
internal/builtins/psd.go Normal file
View File

@@ -0,0 +1,8 @@
//go:build psd || core || full
// +build psd core full
package builtins
import (
_ "github.com/coalaura/ffwebp/internal/codec/psd"
)

82
internal/codec/psd/psd.go Normal file
View File

@@ -0,0 +1,82 @@
package psd
import (
"bytes"
"fmt"
"image"
"io"
"github.com/oov/psd"
"github.com/coalaura/ffwebp/internal/codec"
"github.com/coalaura/ffwebp/internal/logx"
"github.com/coalaura/ffwebp/internal/opts"
"github.com/urfave/cli/v3"
)
var (
skipMerged bool
)
func init() {
codec.Register(impl{})
}
type impl struct{}
func (impl) String() string {
return "psd"
}
func (impl) Extensions() []string {
return []string{"psd", "psb"}
}
func (impl) CanEncode() bool {
return false
}
func (impl) Flags(flags []cli.Flag) []cli.Flag {
return append(flags,
&cli.BoolFlag{
Name: "psd.skip-merged",
Usage: "PSD: skip decoding merged/composite image and only decode layer images (where supported)",
Value: false,
Destination: &skipMerged,
},
)
}
func (impl) Sniff(reader io.ReaderAt) (int, []byte, error) {
magic := []byte{0x38, 0x42, 0x50, 0x53}
buf := make([]byte, 4)
if _, err := reader.ReadAt(buf, 0); err != nil {
return 0, nil, err
}
if bytes.Equal(buf, magic) {
return 100, magic, nil
}
return 0, nil, nil
}
func (impl) Decode(reader io.Reader) (image.Image, error) {
logx.Printf("psd: skipMerged=%t\n", skipMerged)
img, _, err := psd.Decode(reader, &psd.DecodeOptions{
SkipMergedImage: skipMerged,
})
if err != nil {
return nil, err
}
return img.Picker, nil
}
func (impl) Encode(writer io.Writer, img image.Image, options opts.Common) error {
return fmt.Errorf("psd: encoding not supported")
}