mirror of
https://github.com/Belphemur/CBZOptimizer.git
synced 2025-10-14 04:28:51 +02:00
feat: add format setting for completion
This commit is contained in:
@@ -1,8 +1,31 @@
|
||||
package constant
|
||||
|
||||
type ConversionFormat string
|
||||
import "github.com/thediveo/enumflag/v2"
|
||||
|
||||
type ConversionFormat enumflag.Flag
|
||||
|
||||
const (
|
||||
ImageFormatWebP ConversionFormat = "webp"
|
||||
ImageFormatUnknown ConversionFormat = ""
|
||||
WebP ConversionFormat = iota
|
||||
)
|
||||
|
||||
var CommandValue = map[ConversionFormat][]string{
|
||||
WebP: {"webp"},
|
||||
}
|
||||
|
||||
var HelpText = enumflag.Help[ConversionFormat]{
|
||||
WebP: "WebP Image Format",
|
||||
}
|
||||
|
||||
var DefaultConversion = WebP
|
||||
|
||||
func (c ConversionFormat) String() string {
|
||||
return CommandValue[c][0]
|
||||
}
|
||||
|
||||
func ListAll() []string {
|
||||
var formats []string
|
||||
for _, names := range CommandValue {
|
||||
formats = append(formats, names[0])
|
||||
}
|
||||
return formats
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ type Converter interface {
|
||||
}
|
||||
|
||||
var converters = map[constant.ConversionFormat]Converter{
|
||||
constant.ImageFormatWebP: webp.New(),
|
||||
constant.WebP: webp.New(),
|
||||
}
|
||||
|
||||
// Available returns a list of available converters.
|
||||
@@ -28,11 +28,11 @@ func Available() []constant.ConversionFormat {
|
||||
// Get returns a packer by name.
|
||||
// If the packer is not available, an error is returned.
|
||||
func Get(name constant.ConversionFormat) (Converter, error) {
|
||||
if packer, ok := converters[name]; ok {
|
||||
return packer, nil
|
||||
if converter, ok := converters[name]; ok {
|
||||
return converter, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("unkown converter \"%s\", available options are %s", name, strings.Join(lo.Map(Available(), func(item constant.ConversionFormat, index int) string {
|
||||
return string(item)
|
||||
return item.String()
|
||||
}), ", "))
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ type Converter struct {
|
||||
}
|
||||
|
||||
func (converter *Converter) Format() (format constant.ConversionFormat) {
|
||||
return constant.ImageFormatWebP
|
||||
return constant.WebP
|
||||
}
|
||||
|
||||
func New() *Converter {
|
||||
@@ -203,8 +203,8 @@ func (converter *Converter) convertPage(container *packer2.PageContainer, qualit
|
||||
return container, nil
|
||||
}
|
||||
|
||||
// convert converts an image to the ImageFormatWebP format. It decodes the image from the input buffer,
|
||||
// encodes it as a ImageFormatWebP file using the webp.Encode() function, and returns the resulting ImageFormatWebP
|
||||
// convert converts an image to the WebP format. It decodes the image from the input buffer,
|
||||
// encodes it as a WebP file using the webp.Encode() function, and returns the resulting WebP
|
||||
// file as a bytes.Buffer.
|
||||
func (converter *Converter) convert(image image.Image, quality uint) (*bytes.Buffer, error) {
|
||||
var buf bytes.Buffer
|
||||
|
Reference in New Issue
Block a user