The Resoc Netlify Image Engine turns Resoc image templates into images via a simple HTTP API. As the name suggests, it should be deployed to Netlify.
- Use this repository as a template to create your own engine.
- Copy your Resoc templates to your engine.
- Deploy your engine to Netlify.
Create your own image engine:
- Go to the GitHub project page, which is probably where you already are.
- Click the "Use this template" button and follow the wizard to create your own repository.
Add your own Resoc image templates:
- Clone your fresh engine repository locally.
- Remove the demo template in
resoc-templates. In other words, removeresoc-templates/title-description. - Copy your existing image templates to
resoc-templates. For example, if you have two templates namedt01andt02, the template manifests will beresoc-templates/t01/resoc.manifest.jsonandresoc-templates/t02/resoc.manifest.json. - Commit and push your changes.
[Optional] Configure the Cross-origin resource sharing (CORS):
- In
netlify.toml, edit theAccess-Control-Allow-Originheader. For example, if your engine is to be used by the Social Images WordPress plugin and your WordPress site is available athttps://blog.example.com, setAccess-Control-Allow-Origin = "https://blog.example.com" - Commit and push your changes.
Deploy your engine to Netlify:
- Login or sign up to Netlify.
- Create a new Netlify site and associate it with your engine GitHub repository. Once the setup is completed, Netlify deploys your engine.
Test your engine:
- Get your engine URL from the Netlify dashboard, eg
https://my-own-resoc-netlify-image-engine.netlify.app. - Visit
[your engine URL]/templates. You should get a JSON document listing your templates. - Visit
[your engine URL]/templates/[your template name]/demos/open-graph.jpg. For example, if you have a template namedt01, visit[your engine URL]/templates/t01/demos/open-graph.jpg. You should get a demo image.
The following entry points are available:
- Template content (manifest, etc.):
/templates/[template-name]/content/[file-name]. For example/templates/my-template/content/resoc.manifest.json. - Image generation:
- GET:
/templates/[template-name]/images/[dimensions].[format]?[parameters]. For example/templates/my-template/images/open-graph.jpg?title=Hello. - POST:
/templates/[template-name]/images/[dimensions].[format]. For example/templates/my-template/images/open-graph.jpg. The body is expected to be a JSON containing parameter values, eg.{ "title": "Hello" }.
- GET:
- Demo image:
/templates/[template-name]/demos/[dimensions].[format]. For example/templates/title-description/demos/twitter-card.jpg
In the entry points above:
[dimensions]can beopen-graph,twitter-cardor an arbitrary resolution such as1000x800.[format]can bejpg,jpegorpng.