-
Notifications
You must be signed in to change notification settings - Fork 18
Photon
Murhaf Sousli edited this page May 6, 2017
·
1 revision
Photon is an image acceleration and modification service for Jetpack-connected WordPress sites. Converted images are cached automatically and served from the WordPress.com CDN. Images can be cropped, resized, and filtered by using a simple API controlled by GET query arguments. When Photon is enabled in Jetpack, images are updated on the fly.
// get the featured image for a post by option name your registered in the root module
wp.photon().getImage(post, optionName)
// get the featured image for a post directly by photon parameters
wp.photon().getByQuery(post, photonParameters)
example
<img [src]="wp.photon().getImage(post, 'large')" />
<img [src]="wp.photon().getImage(post, 'cropped')" />
<img [src]="wp.photon().getImage(post, 'resized')" />
<img [src]="wp.photon().getByArgs(post, { w: 800, h: 400})" />
To use photon.getImage()
you need to register the options you need to use.
Go in the root module where you import WordPressModule:
export function photonOptions() {
// here is 3 options for photon parameters 'large', 'cropped' and 'resize'
return [
{ 'key': 'large', 'value': { w: 800, h: 360 } },
{ 'key': 'cropped', 'value': { crop: "160px,25,1400px,60" } }و
{ 'key': 'resized', 'value': { resize: "400,220" } }
]
}
@NgModule({
imports: [
// ...
WordPressModule.forRoot('https://example.com', photonOptions())
]
})
Check Photon API for the parameters.