Jon-Becker / nft-generator-py

This tool allows users to generate sets of unique images and metadata using weighted layer collections.
MIT License
301 stars 127 forks source link

Make it possible to import configuration files in JSON format #35

Closed tnkerer closed 2 years ago

tnkerer commented 2 years ago

Proposal

Changing the way generate_unique_images works allows it to use an external config.json file instead of hardcoding configs into index.py.

Motivation

I have been thinking about practical applications for this script to simplify its use for the general audience, like people unfamiliar with software development. I planned to create a container image using Docker and serve this script as a microservice. This service would receive a few arguments, like an URL for external storage containing trait layers, the number of NFTs generated, and a config.json to replace the second argument in generate_unique_images(num, config).

The first step would be making it so generate_unique_images(num, config) reads configuration from an external file.

Example

Given the config.json:

{
  "layers": [
    {
      "name": "Background",
      "values": ["Blue", "Orange", "Purple", "Red", "Yellow"],
      "trait_path": "./trait-layers/backgrounds",
      "filename": ["blue", "orange", "purple", "red", "yellow"],
      "weights": [20,20,20,20,20]
    },
    {
      "name": "Foreground",
      "values": ["Python Logo", "Python Logo 32"],
      "trait_path": "./trait-layers/foreground",
      "filename": ["logo", "logo"],
      "weights": [50, 50]
    },
    {
      "name": "Branding",
      "values": ["A Name", "Another Name"],
      "trait_path": "./trait-layers/text",
      "filename": ["text", "text"],
      "weights": [50, 50]
    }
  ],
  "incompatibilities": [
    {
      "layer": "Background",
      "value": "Blue",
      "incompatible_with": ["Python Logo 2"]
    }, 
  ],
  "baseURI": ".",
  "name": "NFT #",
  "description": "This is a description for this NFT series."
}

It is possible to load config.json with something similar to:

user_config = open('config.json')

data = json.load(user_config)

user_config.close()

PS: I am working on something similar on my side.

Jon-Becker commented 2 years ago

Good suggestion. I'll implement this in the next release

Jon-Becker commented 2 years ago

Implemented in v2.0.0