https://github.com/jacobmstein/carbon-api
An unofficial Java API for Carbon. Create and share beautiful images of your source code, dynamically, with Java!
https://github.com/jacobmstein/carbon-api
api carbon carbon-api gradle java maven
Last synced: 5 months ago
JSON representation
An unofficial Java API for Carbon. Create and share beautiful images of your source code, dynamically, with Java!
- Host: GitHub
- URL: https://github.com/jacobmstein/carbon-api
- Owner: jacobmstein
- License: mit
- Created: 2021-10-06T08:07:31.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-26T20:32:14.000Z (over 4 years ago)
- Last Synced: 2025-07-12T07:31:57.830Z (11 months ago)
- Topics: api, carbon, carbon-api, gradle, java, maven
- Language: Java
- Homepage:
- Size: 69.3 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Carbon API
---



**An unofficial Java API for [Carbon](https://carbon.now.sh). Create and share beautiful images of
your source code, *dynamically*, *with Java*!**
```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](https://github.com/jacobmstein/CarbonBot).
## Contents
* [How It Works](#how-it-works)
* [Using Carbon API](#using-carbon-api)
* [Documentation](#documentation)
* [Dependencies](#dependencies)
* [Style](#style)
## How It Works
1. Creates a URI from the specified arguments.
2. Uses [Microsoft Playwright](https://github.com/microsoft/playwright-java) 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.
```gradle
repositories {
mavenCentral()
}
dependencies {
implementation 'sh.stein:carbon-api:VERSION'
}
```
## Documentation
The latest Javadoc is available
[here](https://www.javadoc.io/doc/sh.stein/carbon-api/latest/sh/stein/carbon/package-summary.html).
## Dependencies
* Playwright
* [GitHub](https://github.com/microsoft/playwright-java)
* Playwright requires various dependencies to install browsers,
see [the docs](https://playwright.dev/java/docs/cli#install-system-dependencies).
## Style
The IntelliJ code style files, which are a fork of
the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html), are stored in
the `.idea/codeStyles` directory.