Enhance Your Code Snippets with carbon-now-cli for Stunning Presentations and Improved Readability

Introduction to carbon-now-cli

carbon-now-cli is a command-line interface tool that leverages the amazing Carbon service to create beautiful images of your code snippets. This tool is perfect for developers who want to share well-formatted and visually appealing code snippets on blogs, social media, or during presentations.

Key Features and APIs with Code Examples

1. Installing carbon-now-cli

To install carbon-now-cli, use the following npm command:

npm install -g carbon-now-cli

2. Creating a Simple Code Snippet Image

You can create an image of a code snippet by running:

carbon-now myCodeFile.js

This will generate a beautiful image of your code file.

3. Specifying Output Directory

To save the generated image to a specific directory, you can use:

carbon-now myCodeFile.js --directory /path/to/output

4. Changing the Window Theme

To change the window theme to “dracula”, use:

carbon-now myCodeFile.js --window-theme dracula

5. Using Different Fonts

To use a different font like “Fira Code”, the command would be:

carbon-now myCodeFile.js --font-fami  "Fira Code"

6. Adding Watermarks

If you want to add a watermark to the image:

carbon-now myCodeFile.js --watermark "Your Watermark"

App Example with carbon-now-cli APIs

Let’s create a small app to showcase how you can use carbon-now-cli to automate code snippet image generation and add personalized branding.

Setup

mkdir myCodeSnippetApp
cd myCodeSnippetApp
npm init -y
npm install -g carbon-now-cli

App Code

Create a script named generateSnippet.js:


const { exec } = require('child_process');

const filePath = './exampleCode.js';
const outputDir = './snippets';
const windowTheme = 'seti';
const fontFamily = 'Ubuntu Mono';
const watermark = 'MyCodeBrand';

exec(`carbon-now ${filePath} --directory ${outputDir} --window-theme ${windowTheme} --font-fami ${fontFamily} --watermark "${watermark}"`, (err, stdout, stderr) => {
  if (err) {
    console.error(\`Error: \${stderr}\`);
    return;
  }
  console.log('Snippet image created successfully!');
});

Put some code in exampleCode.js and run:

node generateSnippet.js

You will get a beautiful image of your code snippet with the specified customizations!

Hash: 455813ca0cb66d1192027710d62ef559e64b13814254cd99a3c4ec1cf08000fe

Leave a Reply

Your email address will not be published. Required fields are marked *