Skip to content

Commit

Permalink
[image-url] Added support for the fit-parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
simen authored and rexxars committed Dec 13, 2017
1 parent 1e0969f commit 00f30d9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/@sanity/image-url/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ Make this an url to download the image. Specify the file name that will be sugge

Flips the image.

### `fit(value)`

Configures the fit mode. See the [documentation](https://www.sanity.io/docs/reference/image-urls#fit-object-object) for details.

### `ignoreImageParams()`

Ignore any specifications from the image record (i.e. crop and hotspot).
Expand Down
4 changes: 4 additions & 0 deletions packages/@sanity/image-url/src/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ class ImageUrlBuilder {
return this._withOptions({ignoreImageParams: true})
}

fit(value) {
return this._withOptions({fit: value})
}

// Gets the url based on the submitted parameters
url() {
return urlForImage(this.options)
Expand Down
3 changes: 2 additions & 1 deletion packages/@sanity/image-url/src/urlForImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const SPEC_NAME_TO_URL_NAME_MAPPINGS = [
['maxHeight', 'max-h'],
['minWidth', 'min-w'],
['maxWidth', 'max-w'],
['quality', 'q']
['quality', 'q'],
['fit', 'fit']
]

export default function urlForImage(options) {
Expand Down
3 changes: 2 additions & 1 deletion packages/@sanity/image-url/test/builder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ const cases = [
.forceDownload('a.png')
.flipHorizontal()
.flipVertical()
.fit('crop')
.url()),
expect: 'rect=10,20,30,40&fp-x=10&fp-x=20&flip=hv&fm=png&dl=a.png&blur=50&invert=true&or=90&min-h=150&max-h=300&min-w=100&max-w=200&q=50'
expect: 'rect=10,20,30,40&fp-x=10&fp-x=20&flip=hv&fm=png&dl=a.png&blur=50&invert=true&or=90&min-h=150&max-h=300&min-w=100&max-w=200&q=50&fit=crop'
}
]

Expand Down

0 comments on commit 00f30d9

Please sign in to comment.