Skip to content

Commit

Permalink
added more transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
aldor007 committed Nov 8, 2017
1 parent 583bfe5 commit 053f2e3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
5 changes: 5 additions & 0 deletions config/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ type PresetsYaml struct {
} `yaml:"entropy_crop"`
AutoRotate bool `yaml:"auto_rtate"`
Strip bool `yaml:"strip"`
Format string `yaml:"format"`
Blur struct {
Sigma float64 `yaml:"sigma"`
MinAmpl float64 `yaml:"minAmpl"`
} `yaml:"blur"`
} `yaml:"filters"`
}

Expand Down
8 changes: 8 additions & 0 deletions object/file_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ func presetToTransform(preset config.PresetsYaml) transforms.Transforms {
trans.StripMetadata()
}

if filters.Format != "" {
trans.Format(filters.Format)
}

if filters.Blur.Sigma != 0 {
trans.Blur(filters.Blur.Sigma, filters.Blur.MinAmpl)
}

return trans
}

Expand Down
32 changes: 31 additions & 1 deletion transforms/transforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type Transforms struct {
sigma float64
minAmpl float64

format bimg.ImageType

NotEmpty bool
}

Expand Down Expand Up @@ -76,8 +78,30 @@ func (t *Transforms) Blur(sigma, minAmpl float64) *Transforms {
return t
}

func (t *Transforms) Format(format string) *Transforms {
t.NotEmpty = true
switch format {
case "jpeg", "jpg":
t.format = bimg.JPEG
case "webp":
t.format = bimg.WEBP
case "png":
t.format = bimg.PNG
case "gif":
t.format = bimg.GIF
case "svg":
t.format = bimg.SVG
case "pdf":
t.format = bimg.PDF
default:
t.format = bimg.UNKNOWN
}

return t
}

func (t *Transforms) BimgOptions() bimg.Options {
return bimg.Options{
b := bimg.Options{
Width: t.width,
Height: t.height,
Enlarge: t.enlarge,
Expand All @@ -90,4 +114,10 @@ func (t *Transforms) BimgOptions() bimg.Options {
MinAmpl: t.minAmpl,
},
}

if t.format != bimg.UNKNOWN || t.format != 0 {
b.Type = t.format
}

return b
}

0 comments on commit 053f2e3

Please # to comment.