Skip to main content
This page is a work in progress.
Rank card creation has been the most common use case for Canvacord to this date. Canvacord provides a RankCardBuilder class to create rank cards with ease. The RankCardBuilder class offers a lot of helper methods to customize the rank card to your liking.

API Documentation

Refer to https://canvacord.js.org for the complete API documentation. In the following sections, we will only cover the most common use cases.

Let’s get started

Importing the Required Classes

First, we need to import the Font and RankCardBuilder classes from the canvacord module.

Loading fonts

Canvacord does not load fonts by default. If your use case does not involve writing texts, this step can be omitted. However, rank cards require texts to be written on them, so we need to load the font into canvacord’s font registry. Canvacord by default ships with a font called Geist (by Vercel). This font can be loaded with the Font.loadDefault() method:
If you want to use a custom font instead, you can skip Font.loadDefault() method and utilize Font.fromFile or Font.fromBuffer method to load the font from a file or buffer respectively.
Good to know: Currently only TTF, OTF and WOFF font formats are supported.

Creating a rank card builder

Now that we have loaded the font, we can create a new RankCardBuilder instance. This is a builder class exported by canvacord to specifically create rank cards. It offers a lot of helper methods to customize the rank card to your liking. The following is an example of a rank card builder with common properties set:

Generating the image

Result

xp-card

Advanced Usage

Overriding default texts

The setTextStyles method is used to customize the text styles for different elements in a rank card or leaderboard. This method allows for the modification of default labels for level, experience points (XP), and rank display.

Result

xp-card

Customizing the colors

The setStyles method can be used to customize the colors of different elements in a rank card or leaderboard. This method allows for the modification of the background, progress bar, and text colors, etc. The style object is a key-value pair of the style name and the value to be set. The style behaves similar to css properties.

Syntax 1 (Style object)

Syntax 2 (Tailwind classes)

Examples

Modifying progress bar width

The internal progress calculator may not be suitable for all use cases. You can set a custom progress calculator using the setProgressCalculator method. The progress calculator is a function that returns a number between 0 and 100, representing the progress percentage.

Overriding emoji providers

Canvacord uses the twemoji provider by default. You can override this by using the setGraphemeProvider method. The setGraphemeProvider method accepts a GraphemeProvider enum value.