jacobmstein / carbon-api

An unofficial Java API for Carbon. Create and share beautiful images of your source code, dynamically, with Java!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Carbon API


An unofficial Java API for Carbon. Create and share beautiful images of your source code, dynamically, with Java!

CarbonService carbon = new PlaywrightCarbonService();

ImageOptions options = new ImageOptions.ImageOptionsBuilder()
        .language(ImageOptions.Language.CSharp)
        .fontFamily(ImageOptions.FontFamily.JetBrainsMono)
        .theme(ImageOptions.Theme.Hopscotch)
        .build();

String code = "Console.WriteLine(\"Hello, world!\");";

byte[] image = carbon.getImage(code, options);

// or, read code from a file
image = carbon.getImage(new File("README.md"), options);

Want to use Carbon with Discord? Check out Carbon Bot.

Contents

How It Works

  1. Creates a URI from the specified arguments.
  2. Uses Microsoft Playwright to visit the created URI.
  3. Screenshots the created image.

Using Carbon API

Java versions 11 and up are supported.

Latest stable release:

Gradle

Just include the following in your build.gradle file:

Replace VERSION with a valid Maven release.

repositories {
    mavenCentral()
}

dependencies {
    implementation 'sh.stein:carbon-api:VERSION'
}

Documentation

The latest Javadoc is available here.

Dependencies

  • Playwright
    • GitHub
    • Playwright requires various dependencies to install browsers, see the docs.

Style

The IntelliJ code style files, which are a fork of the Google Java Style Guide, are stored in the .idea/codeStyles directory.

About

An unofficial Java API for Carbon. Create and share beautiful images of your source code, dynamically, with Java!

License:MIT License


Languages

Language:Java 100.0%