Skip to content

An Open-Graph image generator running in a docker container hosted on fly.io

License

Notifications You must be signed in to change notification settings

amir002001/ogmir

Repository files navigation

Contributors Forks Stargazers Issues MIT License


Logo

ogmir

a blazingly-fast, batteries-included-but-swappable, Opengraph image generator rest endpoint using the DevTools API


Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Roadmap
  4. Contributing
  5. License
  6. Contact

About The Project

Ogmir Screenshot

Are you tired of your Twitter links looking like this:

no opengraph

Well, you should check this project out. I made this project out of passion for Go and a lack of a good open-source starting point for generating open graph images using Go.

There are many ways of achieving similar results. Vercel OG Image offers a serverless solution that can only be used on Next.JS. You could also use fogleman/gg to draw a canvas and export that as an image, but you won't have access to fancy CSS, DOM utilities, etc.

The basic idea is to use Go templates to generate HTML on the fly based on query parameters, screenshot the DOM element, and return it as a response.

To enable better performance I've added a caching layer as well using an on-disk SQLite DB. It proves fine for my use case right now. Could very well be hot-swapped for a Redis cache or an S3, Blob Storage solution.

Same concept was also used for a rate-limiter to reduce the abilities of malicious actors. To further improve security you can reject requests that don't come from your bucket.

This is a project I created and will be maintaining for my blog engine at amir.day.

Thank you to the maintainers of Go Fiber and Go Rod for such a well-maintained API. I had a blast writing this and I'm glad to see it works.

I have a fly.toml file in the root directory and a GitHub action you could use to deploy your service as well but feel free to use anything from Azure app service to cloud run, etc. to deploy it.

(back to top)

Built With

  • Golang
  • Sqlite
  • Docker

(back to top)

Getting Started

For the template itself, I suggest using the sample HTML file in the root directory to get a good sense of what you want your markup to look like and then port it over to the template HTML.

For running and debugging the Go code, either rebuild the container every time (the install layers will all be cached and only the build step is repeated), or volume mount the src folder into a slightly modified Alpine image with the required packages installed.

You could also build and run locally if you have the chromium binary in your path. It might be a different name than the one Alpine wants, so you might want to add a sim link or rename it in the code.

Deployment

These steps are for people deploying to fly. Feel free to change it up for your use case

  1. Get a fly.io account
  2. Get and authenticate to the fly CLI
    brew install flyctl
    fly auth login
  3. Clone the repo
    git clone https://github.com/amir002001/ogmir
  4. Create and deploy fly app
    fly launch
  5. Ping your endpoint
    curl -o "image.png" "<my-app>.fly.io/api/v1/ogmir?title=foo&image=bar"

CI/CD

I have it setup to deploy to fly on pushes to main branch, to achieve this, get a deployment token for your app and add it to GitHub secrets. The workflow will pick it up.

(back to top)

Roadmap

  • Limit to only enable calls from my Cloudinary instance
  • add MIT license

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a pull request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Amir Azizafshari - @AmirLovesKiwis - [email protected]

Project Link: https://github.com/amir002001/ogmir

(back to top)

About

An Open-Graph image generator running in a docker container hosted on fly.io

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published