Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(twicpics): fix minor issues and adds custom operations #132

Merged
merged 6 commits into from
Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Adds focusand zoom to TwicPics’ operations
  • Loading branch information
florentb committed Dec 29, 2020
commit 7d2ee0589afe6ed8519a3a30f5c6fafc3f7136c7
7 changes: 7 additions & 0 deletions playground/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@

<h2>JPEG image on TwicPics</h2>
<NuxtImg provider="twicpics" src="/football.jpg" />
<NuxtImg
provider="twicpics"
src="/football.jpg"
width="250"
height="400"
:operations="{ focus: 'auto' }"
/>
<NuxtImg provider="twicpics" src="/football.jpg" width="100" height="100" quality="1" />

<h2>JPEG image on Fastly</h2>
Expand Down
21 changes: 17 additions & 4 deletions src/providers/twicpics/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const operationsGenerator = createOperationsGenerator({
keyMap: {
format: 'output',
quality: 'quality',
background: 'background'
background: 'background',
focus: 'focus',
zoom: 'zoom'
},
valueMap: {
format (value: string) {
Expand All @@ -29,6 +31,19 @@ const operationsGenerator = createOperationsGenerator({
return value.replace('#', '')
}
return value
},
focus: {
auto: 'auto',
faces: 'faces',
north: '50px0p',
northEast: '100px0p',
northWest: '0px0p',
west: '0px50p',
southWest: '100px100p',
south: '50px100p',
southEast: '0px100p',
east: '100px50p',
center: '50px50p'
}
},
joinWith: '/',
Expand All @@ -42,9 +57,7 @@ export const getImage: ProviderGetImage = (src, { modifiers = {}, baseURL = '/'
providerModifiers[fits(fit)] = `${width || '-'}x${height || '-'}`
}
const operations = operationsGenerator(providerModifiers)
const twicpicsOperations = (operations) ? '?twic=v1/' + operations : ''

return {
url: joinURL(baseURL, src + twicpicsOperations)
url: joinURL(baseURL, src + (operations ? ('?twic=v1/' + operations) : ''))
}
}