nftgen 0.0.2 nftgen: ^0.0.2 copied to clipboard
NFT unqiue image generator and metadata analyzer, available on library and command line.
nftgen #
NFT unqiue image generator and metadata analyzer. It can be used as a Dart library or from the command line.
There are still many things to complete or add.
The general procedure is as follow:
- Generate config file based on layers directory
- Adjust probabilities in config file manually
- Generate NFTs and metadata files
- Analyse NFT rarity distribution, backtrace to 2.
- Upload NFT images and get a CID manually
- Update config file with CID manually
- Update all metadata files with CID automatically
- Upload metadata files manually
Which boils down to these commands:
- nftgen config ...
- ( ... )
- nftgen nft ...
- nftgen rarity ...
- ( ... )
- ( ... )
- nftgen cid ...
- ( ... )
Quickstart #
Create a config, generate NFTs and analyze rarity based on the provided example layers:
dart pub global activate nftgen
nftgen config .\assets\layers\ .\assets\config_gen.json 0.0 "Background,Eyeball,Eye color,Iris,Shine,Bottom lid,Top lid"
nftgen nft .\assets\layers\ .\assets\config_gen.json .\assets\images\ .\assets\meta\
// Or create metadata only to validate rarity distribution (Faster)
// Adjust config file until rarity distribution is OK
nftgen nft .\assets\layers\ .\assets\config_gen.json .\assets\images\ .\assets\meta\ metaonly
nftgen rarity .\assets\meta\ .\assets\rarity_nft.csv .\assets\rarity_layers.csv
Config #
{
// how many NFTs to generate
"maxNfts": 250,
// run "nftgen cid" to update the metadata files
"cidCode": "your CID code",
// the order of layer entries matters
"layers": [
{
// shown in generated metadata JSON
"name": "Eyeball",
// your local directory
"directory": "Eyeball",
// probability: 0.0...1.0 = 0...100%
"probability": 1.0,
"weights": {
// probability: 1 / 17
"Red#50.png": 1,
// probability: 16 / 17
"White#50.png": 16
}
},
...
}
Layer: The config
allows for assinging a percentage to each individual layer between 0.0
and 1.0
, setting the probability that this layer will be used in an NFT.
Layer Image: The config
allows for assigning weights to indivividual images of each layer (layer = trait).
Generate: The config
can be generated by pointing to a directory holding all NFT layers. The generated config
will be simplistic.
For example, the following command will generate a config
with
equal weight distribution (0.0
) and respecting the order of the given directories ("c,b,a"
):
nftgen config .\assets\layers\ .\assets\config_gen.json 0.0 "Background,Eyeball,Eye color,Iris,Shine,Bottom lid,Top lid"
The more NFTs to generate, the steeper the weights within each layer have to be, this can be achived setting the exponential factors to 2.0, 3.0, 4.0
etc.
x*2 1,4,9,16,...
x^3 1,8,27,64,125,216,343,512
x^4 1, 16, 81, 256, 625, 1296, 2401, 4096
Also, the probability of the most rare layers can be set to e.g. 0.25, 0.5, 1.0, 2.0
etc.
Todo: Figure out automatic setting of weights and probabilities for nice distribution of NFTs.
How to Use #
Library #
Please refer to the API for details, some functions have additonal parameters.
final sep = Platform.pathSeparator;
final assets = Directory('assets');
final layersDir = Directory('${assets.path}${sep}layers');
final imagesDir = Directory('${assets.path}${sep}images');
final metaDir = Directory('${assets.path}${sep}meta');
final csvNft = File('${assets.path}${sep}rarity_nft.csv');
final csvLayers = File('${assets.path}${sep}rarity_layers.csv');
// Write config JSON based on layers directory.
final Map<String, dynamic> config = Config.generate(layersDir, factor: 3);
final configFile = File('${assets.path}${sep}config_generated.json');
Io.writeJson(configFile, config);
// Generate NFTs based on config JSON.
Nft.generate(configFile, layersDir, imagesDir, metaDir);
// Analyze generated NFT metadata and save it
final nftAnalysis = Rarity.nfts(metaDir);
final layersAnalysis = Rarity.layers(metaDir);
Io.save(nftAnalysis, csvNft);
Io.save(layersAnalysis, csvLayers);
// Update metadata json with CID code given in config.
// Adjust cidCode in config before running this command.
Config.updateCidMetadata(configFile, metaDir);
Command Line #
- Activate shell command:
dart pub global activate nftgen
- Deactivate shell command:
dart pub global deactivate nftgen
USAGE
* Generate a config-json file:
nftgen config <IN-LAYERS-DIR> <OUT-CONFIG-FILE> [<WEIGHT-FACTOR>:3.0]
* Generate NFTs based on a config-json file:
nftgen nft <IN-CONFIG-FILE> <IN-LAYERS-DIR> <OUT-IMAGE-DIR> <OUT-META-DIR>
* Add CID code read from config or given as parameter to metadata files:
nftgen cid <IN-CONFIG-FILE> <OUT-META-DIR> [<CID>, <CID-REPLACE>]
* Generate rarity reports basd on metadata directory:
nftgen rarity <IN-META-DIR> <OUT-RARITY-NFT.CSV> <OUT-RARITY-LAYERS.CSV>
EXAMPLES
* Generate a config with equal weight distribution and ordered layers:
nftgen config .\assets\layers\ .\assets\config_gen.json 0.0 "Background,Eyeball,Eye color,Iris,Shine,Bottom lid,Top lid"
* Generate NFTs based on a config:
nftgen nft .\assets\layers\ .\assets\config_gen.json .\assets\images\ .\assets\meta\
* Add CID code given as parameter to config and metadata:
nftgen cid .\assets\config_gen.json .\assets\meta\ NEW-CID-CODE OLD-CID-CODE
* Replace CID with CID-REPLACE read from config to metadata:
nftgen cid .\assets\config_gen.json .\assets\meta\
* Generate rarity reports basd on metadata directory:
nftgen rarity .\assets\meta\ .\assets\rarity_nft.csv .\assets\rarity_layers.csv
References #
The example layers are from Hashlips (MIT livense):
https://github.com/HashLips/hashlips_art_engine
License #
MIT