Browse Source

Merge commit '8b372c12602c590e19da48db357490de616b3f5a' into HEAD

feature/add-more-image-steps
Jenkins 3 years ago
parent
commit
b7a12dbc66
  1. 6
      README.md
  2. 2
      config/example.json
  3. 15
      pipelines/pipeline.go
  4. 40
      pipelines/pipeline_test.go

6
README.md

@ -105,7 +105,7 @@ Authorization: Bearer <Token>
} }
], ],
"output": { "output": {
"format": 0,
"format": "jpg",
"quality": 90 "quality": 90
} }
} }
@ -148,13 +148,13 @@ Available pipeline `type`s: `0` (Image), `1` (Video)
The image pipeline offers the following additional output options. The image pipeline offers the following additional output options.
Available `format` types: `0` (jpeg)
Available `format` types: `jpg` (or `jpeg`), `png`, `gif`, `tif` (or `tiff`) and `bmp`
The `quality` field can contain any integer between 1 and 100. The `quality` field can contain any integer between 1 and 100.
```json ```json
{ {
"output": { "output": {
"format": 0,
"format": "jpg",
"quality": 90 "quality": 90
} }
} }

2
config/example.json

@ -33,7 +33,7 @@
} }
], ],
"output": { "output": {
"format": 0,
"format": "jpg",
"quality": 90 "quality": 90
} }
} }

15
pipelines/pipeline.go

@ -38,8 +38,8 @@ type Pipeline struct {
RemoveMetadata bool `json:"remove_metadata" faker:"-"` RemoveMetadata bool `json:"remove_metadata" faker:"-"`
Steps []Step `json:"steps" faker:"-"` Steps []Step `json:"steps" faker:"-"`
Output struct { Output struct {
Format int `json:"format"`
Quality int `json:"quality"`
Format string `json:"format"`
Quality int `json:"quality"`
} `json:"output" faker:"-"` } `json:"output" faker:"-"`
} }
@ -61,7 +61,16 @@ func (p Pipeline) Run(srcPath, bucketName string, storageProvider storage.IStora
} }
} }
format := imaging.Format(p.Output.Format)
outputFormat := p.Output.Format
if outputFormat == "" {
outputFormat = "jpg"
}
format, err := imaging.FormatFromExtension(outputFormat)
if err != nil {
return "", errors.New(fmt.Sprintf("output format '%s' is not supported", outputFormat))
}
var options []imaging.EncodeOption var options []imaging.EncodeOption
if p.Output.Quality != 0 { if p.Output.Quality != 0 {

40
pipelines/pipeline_test.go

@ -362,4 +362,44 @@ func TestEncoding(t *testing.T) {
os.Remove(storageProvider.GetPath(Bucket, "source.jpg")) os.Remove(storageProvider.GetPath(Bucket, "source.jpg"))
os.Remove(storageProvider.GetPath(Bucket, dest)) os.Remove(storageProvider.GetPath(Bucket, dest))
}) })
t.Run("Wrong output format results in error", func(t *testing.T) {
const InvalidPayload string = `{
"name": "example pipeline",
"type": 1,
"removeMetadata": false,
"steps": [
{
"name": "resize image",
"type": 0,
"options": {
"width": 1280,
"height": 720,
"upscale": false
}
}
],
"output": {
"format": "foo",
"quality": 50
}
}`
wd, _ := os.Getwd()
pipe := DeserializePipelines([][]byte{[]byte(InvalidPayload)})[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
_, err = pipe.Run("source.jpg", Bucket, storageProvider)
assert.EqualError(t, err, "output format 'foo' is not supported")
// clean up
os.Remove(storageProvider.GetPath(Bucket, "source.jpg"))
})
} }
Loading…
Cancel
Save