Skip to content

Commit

Permalink
fix(cloudinary): handle blur modifier correctly (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrikBird authored Sep 29, 2023
1 parent adbdff3 commit a5fe841
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/runtime/providers/cloudinary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const operationsGenerator = createOperationsGenerator({
colorSpace: 'cs',
customFunc: 'fn',
density: 'dn',
aspectRatio: 'ar'
aspectRatio: 'ar',
blur: 'e_blur'
},
valueMap: {
fit: {
Expand Down Expand Up @@ -73,7 +74,7 @@ const operationsGenerator = createOperationsGenerator({
}
},
joinWith: ',',
formatter: (key, value) => `${key}_${value}`
formatter: (key, value) => key.includes('_') ? `${key}:${value}` : `${key}_${value}`
})

const defaultModifiers = {
Expand Down
20 changes: 20 additions & 0 deletions test/unit/providers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ describe('Providers', () => {
})
})

it('cloudinary blur param', () => {
const providerOptions = {
baseURL: 'https://res.cloudinary.com/demo/image/fetch/'
}
// see: https://cloudinary.com/documentation/fetch_remote_images#remote_image_fetch_url
const remoteUrl = 'https://upload.wikimedia.org/wikipedia/commons/1/13/Benedict_Cumberbatch_2011.png'
const generated = cloudinary.getImage(
remoteUrl,
{
modifiers: {
blur: 100
},
...providerOptions
}, emptyContext
)
expect(generated).toMatchObject({
url: `https://res.cloudinary.com/demo/image/fetch/f_auto,q_auto,e_blur:100/${remoteUrl}`
})
})

it('cloudinary upload', () => {
const providerOptions = {
baseURL: 'https://res.cloudinary.com/demo/image/upload/remote'
Expand Down

0 comments on commit a5fe841

Please sign in to comment.