mirror of
https://github.com/coalaura/ffwebp.git
synced 2025-09-08 22:09:55 +00:00
psd
This commit is contained in:
@@ -5,7 +5,7 @@ FFWebP is a command line utility for converting images between multiple formats.
|
|||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Pure Go implementation with no external runtime dependencies
|
- Pure Go implementation with no external runtime dependencies
|
||||||
- Supports AVIF, BMP, GIF, ICO, JPEG, JPEGXL, PNG, PNM (PBM/PGM/PPM/PAM), TIFF and WebP
|
- Supports AVIF, BMP, GIF, ICO, JPEG, JPEGXL, PNG, PNM (PBM/PGM/PPM/PAM), PSD (no encoding), TIFF and WebP
|
||||||
- Lossy or lossless output with configurable quality
|
- Lossy or lossless output with configurable quality
|
||||||
- Output codec selected from the output file extension when `--codec` is omitted
|
- Output codec selected from the output file extension when `--codec` is omitted
|
||||||
- Full set of format-specific flags for every supported format (see `ffwebp --help`)
|
- Full set of format-specific flags for every supported format (see `ffwebp --help`)
|
||||||
|
2
go.mod
2
go.mod
@@ -9,6 +9,7 @@ require (
|
|||||||
github.com/gen2brain/jpegxl v0.4.5
|
github.com/gen2brain/jpegxl v0.4.5
|
||||||
github.com/gen2brain/webp v0.5.5
|
github.com/gen2brain/webp v0.5.5
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||||
|
github.com/oov/psd v0.0.0-20220121172623-5db5eafcecbb
|
||||||
github.com/sergeymakinen/go-ico v1.0.0-beta.0
|
github.com/sergeymakinen/go-ico v1.0.0-beta.0
|
||||||
github.com/spakin/netpbm v1.3.2
|
github.com/spakin/netpbm v1.3.2
|
||||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8
|
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8
|
||||||
@@ -16,6 +17,7 @@ require (
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/ebitengine/purego v0.8.3 // indirect
|
github.com/ebitengine/purego v0.8.3 // indirect
|
||||||
|
github.com/gopherjs/gopherjs v1.17.2 // indirect
|
||||||
github.com/sergeymakinen/go-bmp v1.0.0 // indirect
|
github.com/sergeymakinen/go-bmp v1.0.0 // indirect
|
||||||
github.com/tetratelabs/wazero v1.9.0 // indirect
|
github.com/tetratelabs/wazero v1.9.0 // indirect
|
||||||
)
|
)
|
||||||
|
4
go.sum
4
go.sum
@@ -8,8 +8,12 @@ github.com/gen2brain/jpegxl v0.4.5 h1:TWpVEn5xkIfsswzkjHBArd0Cc9AE0tbjBSoa0jDsrb
|
|||||||
github.com/gen2brain/jpegxl v0.4.5/go.mod h1:4kWYJ18xCEuO2vzocYdGpeqNJ990/Gjy3uLMg5TBN6I=
|
github.com/gen2brain/jpegxl v0.4.5/go.mod h1:4kWYJ18xCEuO2vzocYdGpeqNJ990/Gjy3uLMg5TBN6I=
|
||||||
github.com/gen2brain/webp v0.5.5 h1:MvQR75yIPU/9nSqYT5h13k4URaJK3gf9tgz/ksRbyEg=
|
github.com/gen2brain/webp v0.5.5 h1:MvQR75yIPU/9nSqYT5h13k4URaJK3gf9tgz/ksRbyEg=
|
||||||
github.com/gen2brain/webp v0.5.5/go.mod h1:xOSMzp4aROt2KFW++9qcK/RBTOVC2S9tJG66ip/9Oc0=
|
github.com/gen2brain/webp v0.5.5/go.mod h1:xOSMzp4aROt2KFW++9qcK/RBTOVC2S9tJG66ip/9Oc0=
|
||||||
|
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
|
||||||
|
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||||
|
github.com/oov/psd v0.0.0-20220121172623-5db5eafcecbb h1:JF9kOhBBk4WPF7luXFu5yR+WgaFm9L/KiHJHhU9vDwA=
|
||||||
|
github.com/oov/psd v0.0.0-20220121172623-5db5eafcecbb/go.mod h1:GHI1bnmAcbp96z6LNfBJvtrjxhaXGkbsk967utPlvL8=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/sergeymakinen/go-bmp v1.0.0 h1:SdGTzp9WvCV0A1V0mBeaS7kQAwNLdVJbmHlqNWq0R+M=
|
github.com/sergeymakinen/go-bmp v1.0.0 h1:SdGTzp9WvCV0A1V0mBeaS7kQAwNLdVJbmHlqNWq0R+M=
|
||||||
|
8
internal/builtins/psd.go
Normal file
8
internal/builtins/psd.go
Normal 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
82
internal/codec/psd/psd.go
Normal 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")
|
||||||
|
}
|
BIN
test/image.psd
Normal file
BIN
test/image.psd
Normal file
Binary file not shown.
Reference in New Issue
Block a user