DEV Community

Пан Кіт
Пан Кіт

Posted on

OG Image generator based on SVG template

I like the idea of generating OpenGraph images based on some template. SVG structure looks customizable to me, so I tried to use .svg as an OG image and failed. OpenGrapgh does not support this format.

I have Rails app deployed to Heroku. I found a great idea of how to automate OG image creation here.

What we have to do:

  • Create an SVG template (use ERB to support variables);
  • Add mini_magic or similar lib for SVG to JPG conversion;
  • Create a rake task for generating JPG from SVG;
  • Add rake task to Heroku scheduler;

Created rake task will generate and attach JPG to model (will be uploaded to AWS); Rake task should find records without attached OG image. Sometimes you need to regenerate OG image, so it will be nice to have record-marking functionality.

This flow allows us to have an SVG template for the OG image, and also will separate CPU consumption (scheduler will use separate Dyno instance).

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay