feat: image variants engine
This commit is contained in:
1 parent
f0845de643
commit
f1d56ef50e
80 files changed
+7312
-84
No files matched your search
@@ -2,6 +2,7 @@ package audit
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/article"
|
||||
"RenewCMS/internal/domain/image"
|
||||
"strconv"
|
||||
"unicode/utf8"
|
||||
)
|
||||
@@ -28,3 +29,34 @@ func ArticleChanges(before article.Article, after article.Article) []Change {
|
||||
}
|
||||
return changes
|
||||
}
|
||||
|
||||
func VariantChanges(before image.VariantSettings, after image.VariantSettings) []Change {
|
||||
changes := []Change{}
|
||||
changes = appendChange(changes, FieldWidth, image.DimensionText(before.Width), image.DimensionText(after.Width))
|
||||
changes = appendChange(changes, FieldHeight, image.DimensionText(before.Height), image.DimensionText(after.Height))
|
||||
changes = appendChange(changes, FieldFit, string(before.Fit), string(after.Fit))
|
||||
changes = appendChange(changes, FieldFormat, string(before.Format), string(after.Format))
|
||||
changes = appendChange(changes, FieldQuality, image.QualityText(before.Quality), image.QualityText(after.Quality))
|
||||
return changes
|
||||
}
|
||||
|
||||
func appendChange(changes []Change, field string, before string, after string) []Change {
|
||||
if before == after {
|
||||
return changes
|
||||
}
|
||||
return append(changes, TextChange(field, before, after))
|
||||
}
|
||||
|
||||
func VariantParams(settings image.VariantSettings) map[string]any {
|
||||
params := map[string]any{ParamFit: string(settings.Fit), ParamFormat: string(settings.Format)}
|
||||
if settings.Width != nil {
|
||||
params[ParamWidth] = *settings.Width
|
||||
}
|
||||
if settings.Height != nil {
|
||||
params[ParamHeight] = *settings.Height
|
||||
}
|
||||
if settings.Quality != nil {
|
||||
params[ParamQuality] = *settings.Quality
|
||||
}
|
||||
return params
|
||||
}
|
||||
Reference in new issue
Block a user