Browse Source

Add invert image step

feature/add-more-image-steps
Roman Zipp 3 years ago
parent
commit
b4dfea7113
  1. 12
      README.md
  2. 11
      pipelines/executable_step.go
  3. 45
      pipelines/pipeline_test.go
  4. 4
      pipelines/step.go

12
README.md

@ -248,6 +248,18 @@ Scales down the image to fit the specified maximum width and height.
}
```
#### Invert
Invert image colors.
**Step definition**:
```json
{
"type": 5
}
```
## Authors
- [Fabian Vowie](https://gogs.informatik.hs-fulda.de/FabianVowie)

11
pipelines/executable_step.go

@ -89,3 +89,14 @@ func (s FitImageStep) Execute(src image.Image) (image.Image, error) {
src = imaging.Fit(src, s.Options.Width, s.Options.Height, imaging.Lanczos)
return src, nil
}
// Invert image
type InvertImageStep struct {
Step
}
func (s InvertImageStep) Execute(src image.Image) (image.Image, error) {
src = imaging.Invert(src)
return src, nil
}

45
pipelines/pipeline_test.go

@ -364,6 +364,51 @@ func TestExecuteSteps(t *testing.T) {
os.Remove(storageProvider.GetPath(Bucket, "source.jpg"))
os.Remove(storageProvider.GetPath(Bucket, dest))
})
t.Run("Image invert step is successful", func(t *testing.T) {
const Bucket string = "pipeline_test_09"
const Payload string = `{
"name": "example pipeline",
"type": 1,
"removeMetadata": false,
"steps": [
{
"name": "invert",
"type": 5
}
]
}`
wd, _ := os.Getwd()
pipe := DeserializePipelines([][]byte{[]byte(Payload)})[0]
storageProvider := storage.GetFileSystemStorageProvider("test", "..")
// copy test file to storage bucket
_, err := storageProvider.StoreExisting(Bucket, "source.jpg", filepath.Join(wd, "../tests/files/900x900.jpg"))
assert.Nil(t, err, "Test file should be readable")
assert.FileExists(t, storageProvider.GetPath(Bucket, "source.jpg"))
// run pipeline steps
dest, err := pipe.Run("source.jpg", Bucket, storageProvider)
assert.Nil(t, err)
assert.FileExists(t, storageProvider.GetPath(Bucket, dest))
// read image config
file, err := storageProvider.OpenFile(Bucket, dest)
assert.Nil(t, err)
imgConf, _, err := image.DecodeConfig(file)
assert.Nil(t, err)
assert.Equal(t, 900, imgConf.Width)
assert.Equal(t, 900, imgConf.Height)
// clean up
os.Remove(storageProvider.GetPath(Bucket, "source.jpg"))
os.Remove(storageProvider.GetPath(Bucket, dest))
})
}
// output options

4
pipelines/step.go

@ -13,6 +13,7 @@ const (
TypeFlipImageStep
TypeGrayscaleImageStep
TypeFitImageStep
TypeInvertImageStep
)
type Step struct {
@ -52,6 +53,9 @@ func (s Step) GetExecutable() (IExecutableStep, error) {
}
return step, nil
case TypeInvertImageStep:
return InvertImageStep{}, nil
case TypeGrayscaleImageStep:
return GrayscaleImageStep{}, nil
}

Loading…
Cancel
Save