Skip to content

Commit

Permalink
feature: implement interlace parameter (#273)
Browse files Browse the repository at this point in the history
Co-authored-by: Tom <tomas@aparicio.me>
  • Loading branch information
samuelmjn and h2non authored Feb 7, 2020
1 parent 57a6793 commit 59fd1ec
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ Image measures are always in pixels, unless otherwise indicated.
- **minampl** `float` - Minimum amplitude of the gaussian filter to use when blurring an image. Default: Example: `0.5`
- **operations** `json` - Pipeline of image operation transformations defined as URL safe encoded JSON array. See [pipeline](#get--post-pipeline) endpoints for more details.
- **sign** `string` - URL signature (URL-safe Base64-encoded HMAC digest)
- **interlace** `bool` - Use progressive / interlaced format of the image output. Defaults to `false`
- **aspectratio** `string` - Apply aspect ratio by giving either image's height or width. Exampe: `16:9`

#### GET /
Expand Down Expand Up @@ -654,9 +655,9 @@ Crop the image by a given width or height. Image ratio is maintained
- minampl `float`
- gravity `string`
- field `string` - Only POST and `multipart/form` payloads
- interlace `bool`
- aspectratio `string`


#### GET | POST /smartcrop
Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`

Expand Down Expand Up @@ -686,6 +687,7 @@ Crop the image by a given width or height using the [libvips](https://github.com
- minampl `float`
- gravity `string`
- field `string` - Only POST and `multipart/form` payloads
- interlace `bool`
- aspectratio `string`

#### GET | POST /resize
Expand Down Expand Up @@ -717,6 +719,7 @@ Resize an image by width or height. Image aspect ratio is maintained
- sigma `float`
- minampl `float`
- field `string` - Only POST and `multipart/form` payloads
- interlace `bool`
- aspectratio `string`

#### GET | POST /enlarge
Expand Down Expand Up @@ -746,6 +749,7 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
- sigma `float`
- minampl `float`
- field `string` - Only POST and `multipart/form` payloads
- interlace `bool`

#### GET | POST /extract
Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
Expand Down Expand Up @@ -777,6 +781,7 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
- sigma `float`
- minampl `float`
- field `string` - Only POST and `multipart/form` payloads
- interlace `bool`
- aspectratio `string`

#### GET | POST /zoom
Expand Down Expand Up @@ -807,6 +812,7 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
- sigma `float`
- minampl `float`
- field `string` - Only POST and `multipart/form` payloads
- interlace `bool`
- aspectratio `string`

#### GET | POST /thumbnail
Expand Down Expand Up @@ -835,6 +841,7 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
- sigma `float`
- minampl `float`
- field `string` - Only POST and `multipart/form` payloads
- interlace `bool`
- aspectratio `string`

#### GET | POST /fit
Expand Down Expand Up @@ -866,6 +873,7 @@ The width and height specify a maximum bounding box for the image.
- sigma `float`
- minampl `float`
- field `string` - Only POST and `multipart/form` payloads
- interlace `bool`
- aspectratio `string`

#### GET | POST /rotate
Expand Down Expand Up @@ -894,6 +902,7 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
- sigma `float`
- minampl `float`
- field `string` - Only POST and `multipart/form` payloads
- interlace `bool`
- aspectratio `string`

#### GET | POST /flip
Expand Down Expand Up @@ -921,6 +930,7 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
- sigma `float`
- minampl `float`
- field `string` - Only POST and `multipart/form` payloads
- interlace `bool`
- aspectratio `string`

#### GET | POST /flop
Expand Down Expand Up @@ -948,6 +958,7 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
- sigma `float`
- minampl `float`
- field `string` - Only POST and `multipart/form` payloads
- interlace `bool`
- aspectratio `string`

#### GET | POST /convert
Expand All @@ -974,6 +985,7 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
- sigma `float`
- minampl `float`
- field `string` - Only POST and `multipart/form` payloads
- interlace `bool`
- aspectratio `string`

#### GET | POST /pipeline
Expand Down Expand Up @@ -1096,6 +1108,7 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
- sigma `float`
- minampl `float`
- field `string` - Only POST and `multipart/form` payloads
- interlace `bool`

#### GET | POST /watermarkimage
Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
Expand Down Expand Up @@ -1125,6 +1138,7 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
- sigma `float`
- minampl `float`
- field `string` - Only POST and `multipart/form` payloads
- interlace `bool`

#### GET | POST /blur
Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
Expand All @@ -1151,6 +1165,7 @@ Accepts: `image/*, multipart/form-data`. Content-Type: `image/*`
- background `string` - Example: `?background=250,20,10`
- colorspace `string`
- field `string` - Only POST and `multipart/form` payloads
- interlace `bool`
- aspectratio `string`

## Support
Expand Down
3 changes: 3 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type ImageOptions struct {
AspectRatio string
Color []uint8
Background []uint8
Interlace bool
Extend bimg.Extend
Gravity bimg.Gravity
Colorspace bimg.Interpretation
Expand All @@ -61,6 +62,7 @@ type IsDefinedField struct {
NoRotation bool
NoProfile bool
StripMetadata bool
Interlace bool
}

// PipelineOperation represents the structure for an operation field.
Expand Down Expand Up @@ -139,6 +141,7 @@ func BimgOptions(o ImageOptions) bimg.Options {
StripMetadata: o.StripMetadata,
Type: ImageType(o.Type),
Rotate: bimg.Angle(o.Rotate),
Interlace: o.Interlace,
}

if len(o.Background) != 0 {
Expand Down
7 changes: 7 additions & 0 deletions params.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var paramTypeCoercions = map[string]Coercion{
"sigma": coerceSigma,
"minampl": coerceMinAmpl,
"operations": coerceOperations,
"interlace": coerceInterlace,
"aspectratio": coerceAspectRatio,
}

Expand Down Expand Up @@ -336,6 +337,12 @@ func coerceOperations(io *ImageOptions, param interface{}) (err error) {
return ErrUnsupportedValue
}

func coerceInterlace(io *ImageOptions, param interface{}) (err error) {
io.Interlace, err = coerceTypeBool(param)
io.IsDefinedField.Interlace = true
return err
}

func buildParamsFromOperation(op PipelineOperation) (ImageOptions, error) {

var options ImageOptions
Expand Down
4 changes: 3 additions & 1 deletion params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestReadParams(t *testing.T) {
q.Add("opacity", "0.2")
q.Add("text", "hello")
q.Add("background", "255,10,20")
q.Add("interlace", "true")

params, err := buildParamsFromQuery(q)
if err != nil {
Expand All @@ -31,7 +32,8 @@ func TestReadParams(t *testing.T) {
params.Text == "hello" &&
params.Background[0] == 255 &&
params.Background[1] == 10 &&
params.Background[2] == 20
params.Background[2] == 20 &&
params.Interlace == true

if assert == false {
t.Error("Invalid params")
Expand Down

0 comments on commit 59fd1ec

Please sign in to comment.