TavernAI card lib is a library for loading, modifying and saving TavernAI cards within a dotnet application.
It supports .json
, .png
, .webp
, .jpg
and .jpeg
files. Although some of these formats have been untested so far.
using TavernAICardLib;
- Loading a file from a
.json
TavernAiCard card = TavernAiCard.Load("character.json");
- Loading a file from an
image
TavernAiCard card = TavernAiCard.Load("character.png");
- Saving a
.json
card.Save("character_saved.json");
- Saving a
.png
card.Save("character_saved.png");
- Reading the name
string name = card.Name;
- Writing the name
card.Name = "New name";
- Create an empty image for the card (Windows only).
// Check if bitmap image editing is supported, Windows only.
if (TavernAiCard.ImageFullySupported())
{
// Create a transparent bitmap
card.Image = new Bitmap(400, 600);
}
- Setting the image to another image file
// Set Image to null in case it was already set from loading from an image file on Windows.
card.Image = null;
card.ImagePath = "path/to/the/image.png";
- Create simple card
// Instantiating, then setting properties
TavernAiCard card = new TavernAiCard();
// Giving a name
card.Name = "Name";
// Instantiating and declaring properties
TavernAiCard card = new TavernAiCard(){
Name = "Name"
};
- Create card with image from path
// Instantiating, then setting properties
TavernAiCard card = new TavernAiCard("path/to/the/image.png");
// Giving a name
card.Name = "Name";
// Instantiating and declaring properties
TavernAiCard card = new TavernAiCard("path/to/the/image.png"){
Name = "Name"
};
- Create card with image bitmap (Windows only)
// Instantiating, then setting properties
TavernAiCard card = new TavernAiCard(new Bitmap(400, 600));
// Giving a name
card.Name = "Name";
// Instantiating and declaring properties
TavernAiCard card = new TavernAiCard(new Bitmap(400, 600)){
Name = "Name"
};
- Converting from
.json
to.png
with an image from an existing file
TavernAiCard card = TavernAiCard.Load("character.json");
card.ImagePath = "path/to/the/image.png";
card.Save("character_saved.png");
- Converting from
.json
to.png
with a bitmap image (Windows only)
TavernAiCard card = TavernAiCard.Load("character.json");
card.Image = new Bitmap(400, 400);
card.Save("character_saved.png");
- Converting from
.png
to.json
TavernAiCard card = TavernAiCard.Load("character.png");
card.Save("character_saved.json");