Example Carbon code image

Have you ever wanted to share a code snippet on social media and while requiring the formatting to stay intact and for it to look beautiful? I know that I have, which is how I found Carbon, an OSS code-to-image tool that solves this exact problem.

Carbon with some example code.

Below you can see a screenshot of the utility to help you get an idea of how lovely the output can be. It offers a complete set of configuration options, which enable you to customise precisely how the code snippet will look. It’s even possible to export & import configurations, allowing you customise further than the GUI in the portal allows. Using a custom configuration file is how I set the background to be transparent! (configuration JSON below)

{
   "paddingVertical":"21px",
   "paddingHorizontal":"19px",
   "backgroundImage":null,
   "backgroundImageSelection":null,
   "backgroundMode":"color",
   "backgroundColor":"rgba(0,0,0,0)",
   "dropShadow":true,
   "dropShadowOffsetY":"3px",
   "dropShadowBlurRadius":"13px",
   "theme":"vscode",
   "windowTheme":"none",
   "language":"text/x-csharp",
   "fontFamily":"Monoid",
   "fontSize":"14px",
   "lineHeight":"133%",
   "windowControls":false,
   "widthAdjustment":false,
   "lineNumbers":false,
   "firstLineNumber":1,
   "exportSize":"2x",
   "watermark":false,
   "squaredImage":false,
   "hiddenCharacters":false,
   "name":""
}

Carbon Desktop App

Carbon is not only available online, but it’s also possible to use it as a desktop app with offline support as a result of Microsoft’s Edge PWA support.

Whilst this is all groovy, I found myself wanted a sleeker option for creating code snippets from Visual Studio 2019. It’s this reason that I started developing my first Visual Studio Extension!

Send to Carbon – VS2019 Extension

The extension is crazy simple to use. Highlight your C#, F# or VB code that you want to convert to a beautiful image, right click in the editor and hit ‘Send to Carbon’. This launches your default browser and with a bit of magic, your image is ready to export.

Why only .NET Languages?

It’s a temporary limitation due to mostly wanting the speed boost of limited language support. There is also a second reason, which is a dependency on Roslyn. The extension uses the Formatter.Format method to ensure proper formatting of the code snippet before sharing with Carbon and while easy enough to work around; I’ve yet to complete the implementation of this. In the next version, the extension will support C#, F#, VB.NET, XAML, HTML and JSON.

Install the preview today!

Build from Code

You can download a clone of the source from GitHub. You’ll need to have the Visual Studio SDK installed to build the project.

GitHub Release

Alternatively, if building the project isn’t your idea of fun then grab a pre-built release from GitHub Releases.

Visual Studio Market Place

Coming Soon, once the extension is completed.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.