mirror of
https://github.com/coalaura/ffwebp.git
synced 2025-09-08 13:59:54 +00:00
add --input.codec
This commit is contained in:
@@ -46,6 +46,10 @@ func main() {
|
|||||||
Aliases: []string{"c"},
|
Aliases: []string{"c"},
|
||||||
Usage: "force output codec (jpeg, png, ...)",
|
Usage: "force output codec (jpeg, png, ...)",
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "input.codec",
|
||||||
|
Usage: "force input codec, skip sniffing (jpeg, png, ...)",
|
||||||
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "sniff",
|
Name: "sniff",
|
||||||
Aliases: []string{"f"},
|
Aliases: []string{"f"},
|
||||||
@@ -265,7 +269,9 @@ func run(_ context.Context, cmd *cli.Command) error {
|
|||||||
func processOne(input, output string, cmd *cli.Command, common *opts.Common, logger io.Writer) error {
|
func processOne(input, output string, cmd *cli.Command, common *opts.Common, logger io.Writer) error {
|
||||||
var (
|
var (
|
||||||
reader io.Reader = os.Stdin
|
reader io.Reader = os.Stdin
|
||||||
writer *countWriter = &countWriter{w: os.Stdout}
|
writer *countWriter = &countWriter{
|
||||||
|
w: os.Stdout,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if input != "-" {
|
if input != "-" {
|
||||||
@@ -283,14 +289,16 @@ func processOne(input, output string, cmd *cli.Command, common *opts.Common, log
|
|||||||
logx.Fprintf(logger, "reading input from <stdin>\n")
|
logx.Fprintf(logger, "reading input from <stdin>\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
sniffed, reader2, err := codec.Sniff(reader, input, cmd.Bool("sniff"))
|
forced := cmd.String("input.codec")
|
||||||
|
|
||||||
|
sniffed, reader2, err := codec.Sniff(reader, input, forced, cmd.Bool("sniff"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
reader = reader2
|
reader = reader2
|
||||||
|
|
||||||
logx.Fprintf(logger, "sniffed codec: %s (%q)\n", sniffed.Codec, sniffed)
|
logx.Fprintf(logger, "sniffed codec: %s (%q, forced=%v)\n", sniffed.Codec, sniffed, forced != "")
|
||||||
|
|
||||||
var mappedFromDir bool
|
var mappedFromDir bool
|
||||||
|
|
||||||
|
@@ -30,7 +30,20 @@ func (s *Sniffed) String() string {
|
|||||||
return builder.String()
|
return builder.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Sniff(reader io.Reader, input string, ignoreExtension bool) (*Sniffed, io.Reader, error) {
|
func Sniff(reader io.Reader, input, force string, ignoreExtension bool) (*Sniffed, io.Reader, error) {
|
||||||
|
if force != "" {
|
||||||
|
codec, err := FindCodec(strings.ToLower(force), false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Sniffed{
|
||||||
|
Header: []byte(force),
|
||||||
|
Confidence: 100,
|
||||||
|
Codec: codec,
|
||||||
|
}, reader, nil
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
hintedExt string
|
hintedExt string
|
||||||
hintedCodec Codec
|
hintedCodec Codec
|
||||||
@@ -38,6 +51,7 @@ func Sniff(reader io.Reader, input string, ignoreExtension bool) (*Sniffed, io.R
|
|||||||
|
|
||||||
if !ignoreExtension {
|
if !ignoreExtension {
|
||||||
hintedExt = strings.ToLower(strings.TrimPrefix(filepath.Ext(input), "."))
|
hintedExt = strings.ToLower(strings.TrimPrefix(filepath.Ext(input), "."))
|
||||||
|
|
||||||
if hintedExt != "" {
|
if hintedExt != "" {
|
||||||
hintedCodec, _ = FindCodec(hintedExt, false)
|
hintedCodec, _ = FindCodec(hintedExt, false)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user