Code Monkey home page Code Monkey logo

pig-script's Introduction

logo-image.png

This is a simple repo set up to help you script programmatic image generation.

The most typical use is for og-image metadata, but it's also useful for compositing images to upload for the GitHub or Replicate preview images, etc.

In the past, I tried to do this for Sparkl, and failed to do this headlessly with wkhtmltoimage, phantomjs, and html-to-image. I finally ended up using PIL - but that was quite a bad experience given that you can't write HTML/CSS and instead need to imperatively draw everything.

Currently, the best option is via Vercel OG or directly using their dependencies.

However, the Vercel option needs you to put up a Vercel deployment, and they don't document the Node.js path super well. This repo tries to do that + provide examples.

Usage

  • Clone this repo
  • Add or modify one or more templates in src, take a look at logo.tsx and template.tsx for examples.
  • Modify index.ts to run the template(s) one or more times and write the outputs wherever you'd like
  • Run npm run main to generate the image(s)

Images, Fonts & More

  • Remote images can be directly referenced in image tags
  • Local images need to be converted to ArrayBuffers first, see logo.tsx for an example
  • Fonts need to be imported, see index.tsx for the example.
  • This is ultimately a wrapper around @vercel/og, so you should read their docs for more complex behavior.

FAQ

  • Q: How do I preview the image during development?
    • A: I've not found a great answer yet, ideally this repo would also host a simple webserver, so you could preview the image + inspect HTML. For now, I'd recommend using either the Vercel Playground or just keeping open an image viewer while you rerun npm run main

pig-script's People

Contributors

venkr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.