feat: image variants engine
This commit is contained in:
1 parent
f0845de643
commit
f1d56ef50e
80 files changed
+7312
-84
No files matched your search
@@ -0,0 +1,31 @@
|
||||
package useCases
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/image"
|
||||
"slices"
|
||||
)
|
||||
|
||||
type VariantDefinitionCommand struct {
|
||||
Width *int
|
||||
Height *int
|
||||
Fit string
|
||||
Format string
|
||||
Quality *int
|
||||
}
|
||||
|
||||
func (c VariantDefinitionCommand) settings(encodable []image.VariantFormat) (image.VariantSettings, error) {
|
||||
settings, err := image.VariantSettings{
|
||||
Width: c.Width,
|
||||
Height: c.Height,
|
||||
Fit: image.VariantFit(c.Fit),
|
||||
Format: image.VariantFormat(c.Format),
|
||||
Quality: c.Quality,
|
||||
}.Normalized()
|
||||
if err != nil {
|
||||
return image.VariantSettings{}, err
|
||||
}
|
||||
if !slices.Contains(encodable, settings.Format) {
|
||||
return image.VariantSettings{}, image.ErrVariantFormatUnavailable
|
||||
}
|
||||
return settings, nil
|
||||
}
|
||||
Reference in new issue
Block a user