Skip to content

Commit

Permalink
Add support for Thumbor
Browse files Browse the repository at this point in the history
  • Loading branch information
c0b41 committed Oct 30, 2020
1 parent a666072 commit e8bc851
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/basic-features/image-optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ The following Image Optimization cloud providers are supported:
- [Imgix](https://www.imgix.com): `loader: 'imgix'`
- [Cloudinary](https://cloudinary.com): `loader: 'cloudinary'`
- [Akamai](https://www.akamai.com): `loader: 'akamai'`
- [Thumbor](http://thumbor.org/): `loader: 'thumbor'`

## Caching

Expand Down
15 changes: 14 additions & 1 deletion packages/next/client/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ const loaders = new Map<LoaderKey, (props: LoaderProps) => string>([
['imgix', imgixLoader],
['cloudinary', cloudinaryLoader],
['akamai', akamaiLoader],
['thumbor', thumborLoader],
['default', defaultLoader],
])

type LoaderKey = 'imgix' | 'cloudinary' | 'akamai' | 'default'
type LoaderKey = 'imgix' | 'cloudinary' | 'akamai' | 'thumbor' | 'default'

const VALID_LAYOUT_VALUES = [
'fixed',
Expand Down Expand Up @@ -470,6 +471,18 @@ function cloudinaryLoader({ root, src, width, quality }: LoaderProps): string {
return `${root}${paramsString}${normalizeSrc(src)}`
}

function thumborLoader({ root, src, width, quality }: LoaderProps): string {
const params = [`${width}x0`]
let paramsString = ''
if (quality) {
params.push(`filters:quality(${quality})`)
}
if (params.length) {
paramsString = params.join('/') + '/'
}
return `${root}${paramsString}${normalizeSrc(src)}`
}

function defaultLoader({ root, src, width, quality }: LoaderProps): string {
if (process.env.NODE_ENV !== 'production') {
const missingValues = []
Expand Down

0 comments on commit e8bc851

Please sign in to comment.