Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
gitmylo committed Jun 8, 2023
1 parent 75f2346 commit c2d723f
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
10 changes: 9 additions & 1 deletion TavernAICardLib/TavernAiCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ public static bool ImageFullySupported()
public TavernAiCard(string? imagePath, Image? image)
{
this.ImagePath = imagePath;
this.Image = image;
if (image == null && imagePath != null && ImageFullySupported())
{
this.Image = new Bitmap(imagePath);
}
else this.Image = image;
}

public TavernAiCard() {}
public TavernAiCard(string? imagePath) : this(imagePath, null) {}
public TavernAiCard(Image? image) : this(null, image) {}

public static string[] ImageFileTypes = {".png", ".webp", ".jpg", ".jpeg"};
public static string[] JsonFileTypes = {".json"};

Expand Down
75 changes: 72 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,33 @@
* [TavernAI card lib .net](#tavernai-card-lib-net)
* [Description](#description)
* [Examples](#examples)
* [Importing](#importing)
* [Loading](#loading)
* [Saving](#saving)
* [Data reading and writing](#data-reading-and-writing)
* [Image modification](#image-modification)
* [Card creation](#card-creation)
* [Card format conversion](#card-format-conversion)
<!-- TOC -->

# Description
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.
It supports `.json`, `.png`, `.webp`, `.jpg` and `.jpeg` files. Although some of these formats have been untested so far.

# Examples

# Importing
```csharp
using TavernAICardLib;
```

## Loading
* Loading a file from a JSON
* Loading a file from a `.json`
```csharp
TavernAiCard card = TavernAiCard.Load("character.json");
```
* Loading a file from an image
* Loading a file from an `image`
```csharp
TavernAiCard card = TavernAiCard.Load("character.png");
```
Expand Down Expand Up @@ -68,3 +76,64 @@ if (TavernAiCard.ImageFullySupported())
card.Image = null;
card.ImagePath = "path/to/the/image.png";
```

## Card creation
* Create simple card
```csharp
// 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
```csharp
// 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**)
```csharp
// 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"
};
```

## Card format conversion
* Converting from `.json` to `.png` with an image from an existing file
```csharp
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**)
```csharp
TavernAiCard card = TavernAiCard.Load("character.json");
card.Image = new Bitmap(400, 400);
card.Save("character_saved.png");
```

* Converting from `.png` to `.json`
```csharp
TavernAiCard card = TavernAiCard.Load("character.png");
card.Save("character_saved.json");
```

0 comments on commit c2d723f

Please sign in to comment.