Unique image & metadata generation using weighted layer collections.

Overview

nft-generator-py

nft-generator-py is a python based NFT generator which programatically generates unique images using weighted layer files. The program is simple to use, and new layers can be added by adding a new layer object and adding names, weights, and image files to the object. You can View The Demo here.

How it works

  • A call to generate_unique_images(amount, config) is made, which is the meat of the application where all the processing happens.
  • The config object is read and for each object in the layers list, random values are selected and checked for uniqueness against all previously generated metadata files.
  • Once we have amount unique tokens created, we layer them against eachother and output them and their metadata to their respective folders, ./metadata and ./images.

Configuration

{
  "layers": [
    {
      "name": "Background",
      "values": ["Blue", "Orange", "Purple", "Red", "Yellow"],
      "trait_path": "./trait-layers/backgrounds",
      "filename": ["blue", "orange", "purple", "red", "yellow"],
      "weights": [30, 45, 15, 5, 10]
    },
    ...
  ],
  "name": "NFT #"
}

The config object is a dict that contains layers and name objects that can be changed to produce different outputs when running the program. Within metadata files, tokens are named using the configuration's name parameter.

  • In ascending order, tokenIds are appended to the name resulting in NFT metadata names such as NFT #0001.
  • tokenIds are padded to the largest amount generated. IE, generating 999 objects will result in names NFT #001, using the above configuration, and generating 1000 objects will result in NFT #0001.

The layers list contains layer objects that define the layers for the program to use when generating unique tokens. Each layer has a name, which will be displayed as an attribute, values, trait_path, filename, and weights.

  • trait_path refers to the path where the image files in filename can be found. Please note that filenames omit .png, and it will automatically be prepended.

  • weight corresponds with the percent chance that the specific value that weight corresponds to will be selected when the program is run. The weights must add up to 100, or the program will fail.

Troubleshooting

  • All images should be in .png format.
  • All images should be the same size in pixels, IE: 1000x1000.
  • The weight values for each attribute should add up to equal 100.

Credits

This project is completely coded by Jonathan Becker, using no external libraries.

Comments
  • incompatibilities not working for me

    incompatibilities not working for me

    dear friend,

    could not figure out why the incompatibilities is not working for me. is this feature still in development or should it work as described ? help would be much appreciated

    thank you

    
        {
          "name": "BOTS",
          "values": ["Bombed", "Doodle", "Gold", "Green", "Grey", "Ironman", "Rot", "Wood", "Yellow", "Zombie"],
          "trait_path": "./trait-layers/2_BOTS",
          "filename": ["Bombed", "Doodle", "Gold", "Green", "Grey", "Ironman", "Rot", "Wood", "Yellow", "Zombie"],
          "weights": [8, 12, 2, 15, 15, 6, 15, 7, 15, 5]
        },
    	{
          "name": "EYES",
          "values": ["Bullaugen", "Eyes_human", "Hawt_Augen", "Schlitzauge", "Tearsdrops"],
          "trait_path": "./trait-layers/4_EYES",
          "filename": ["Bullaugen", "Eyes_human", "Hawt_Augen", "Schlitzauge", "Tearsdrops"],
          "weights": [20, 20, 20, 20, 20]
        },
    	
    	
    	...
    	
    	
    	 "incompatibilities": [
        {"layer": "BOTS", "value": "Ironman", "incompatible_with": ["Bullaugen"]},
        {"layer": "BOTS", "value": "Ironman", "incompatible_with": ["Eyes_human"]},
        {"layer": "BOTS", "value": "Ironman", "incompatible_with": ["Hawt_Augen"]},
        {"layer": "BOTS", "value": "Ironman", "incompatible_with": ["Schlitzauge"]},
        {"layer": "BOTS", "value": "Ironman", "incompatible_with": ["Tearsdrops"]}
    
      ],
    
    
    invalid issue 
    opened by Stadtrausch 12
  • Cant Generate

    Cant Generate

    Hello, First of all thank you for amazing work.

    I'm very noobie, first time trying to do something in .py.

    I just wanted to check if your generator engine is work. I didn't change anything, but all the time have same error

    Exception has occurred: ModuleNotFoundError No module named 'PIL' File "/Users/petre/Desktop/NFT-PY/index.py", line 2, in from PIL import Image

    Could you help me?

    invalid question 
    opened by PetreEP 7
  • Script to update JSON file with proper IPFS Data for images

    Script to update JSON file with proper IPFS Data for images

    Feature Request:

    When deploying the NFT images and metadata to IPFS, it is necessary to first upload the images (and get a unique CID). Then I need to update the JSON files to point at this CID. I can not create the CID in advance of running the generative script (index.py) as I do not have the CID until I upload the images.

    Could a script be added to run after the index.py & once I get the CID to go through all files in the metadata folder and update the baseURI to represent the IPFS CID? (Or regenerate them based on all-object.json?) Obviously the data needs to maintain the connection to the image.

    question issue 
    opened by stocktonellis 7
  • Config Error

    Config Error

    Getting this error when just trying to run the included default settings:

    At line:1 char:30

    • generate_unique_images(amount, config)
    •                          ~
      

    Missing argument in parameter list. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingArgument

    question 
    opened by ccislegend 6
  • Getting List index out of range error.

    Getting List index out of range error.

    When I try to run the program with my attributes, I keep getting this error: Not sure why? I did add more traits and values than the original. Any ideas?

    % python3 index.py

    Traceback (most recent call last): File "/Users/NAME/Desktop/nft-generator/index.py", line 83, in generate_unique_images(8888, { File "/Users/NAME/Desktop/nft-generator/index.py", line 28, in generate_unique_images trait_files[trait["name"]][key] = trait["filename"][x]; IndexError: list index out of range

    opened by stocktonellis 6
  • Invalid syntax in index.py file

    Invalid syntax in index.py file

    Syntax errors detected :

    Line 67: layers[index] = Image.open(f'{config["layers"][index]["trait_path"]}/{trait_files[attr][item[attr]]}.png').convert('RGBA') ^ SyntaxError: invalid syntax

    Any idea how to resolve? Thanks

    invalid issue 
    opened by nickgag626 5
  • Trait counter

    Trait counter

    I added code to count and write used traits to JSON file.

    from collections import Counter
    
    all_token_rarity = []
    for layer in config["layers"]:
      all_token_rarity.append({ layer["name"]: Counter(image[layer["name"]] for image in all_images) })
    
    with open('./metadata/all-rarity.json', 'w') as outfile:
       json.dump(all_token_rarity, outfile, indent=4)
    

    Maybe someone find it useful.

    enhancement 
    opened by mwkemo 4
  • Metadata issue

    Metadata issue

    Hey, Everything works fine, except metadata name and token id inside. For exmp. When 5 image generation have completed I've got:

    In image Folder: 1,2,3,4,5

    In metadata Folder: 0,1,2,3,4 and all objects.

    I have qustion if it's possible to match token id number to metadata number.

    Thanks,

    Petrre

    invalid issue 
    opened by PetreEP 4
  • it is not possible to generate more than 5 nft with my config.

    it is not possible to generate more than 5 nft with my config.

    the process simply dies if I set a value greater than 5, and with a standard code greater than 20 is not generated "The kernel 'Python 3.10.2 64-bit' died. " `generate_unique_images(5, { "layers": [ { "name": "Background", "values": ["Common", "Uncommon", "Rare", "Epic", "Legendary"], "trait_path": "./trait-layers/backgrounds", "filename": ["blue", "orange", "purple", "red", "yellow"], "weights": [40,35,15,9,1] }, { "name": "Foreground", "values": ["Qw, "Qs","Qe","Qr","Qt" ], "trait_path": "./trait-layers/foreground", "filename": ["qw", "qs", "qe", "qr", "qt"], "weights": [20,20,20,20,20] },

    ], "incompatibilities": [ { "layer": "Foreground", "value": "Qw", "incompatible_with": ["Uncommon", "Rare", "Epic", "Legendary"] }, { "layer": "Foreground", "value": "Qs", "incompatible_with": ["Common", "Rare", "Epic", "Legendary"] }, { "layer": "Foreground", "value": "Qe", "incompatible_with": ["Common", "Uncommon", "Epic", "Legendary"] }, { "layer": "Foreground", "value": "Qr", "incompatible_with": ["Common", "Uncommon", "Rare", "Legendary"] }, { "layer": "Foreground", "value": "Qt", "incompatible_with": ["Common", "Uncommon", "Rare", "Epic"] }, ], "baseURI": ".", "name": "NFT #", "description": "Generation 0" })`

    duplicate 
    opened by Puffini 4
  • Increasing amount causes failure after adding more incompatibilities

    Increasing amount causes failure after adding more incompatibilities

    Hi there, thanks for providing this resource. It helps for learning. Testing, I have been growing the number of incompatibilities between traits and layers. Removing a few target blocks of incompatibilities, you can generate 1000 or more. Adding those sections back will see premature finish with exit code -1073741571 (0xC00000FD) However you can then generate about 200 but exceeding that will again result in EC: -1073741571 (0xC00000FD)

    Does it need more assets in this situation due to growing the number of incompatibilities limiting the total number of possible outcomes below 200?

    bug 
    opened by Atekom 4
  • Value Error:('The number of weights does not match the population')

    Value Error:('The number of weights does not match the population')

    So there's a weird error that happened when I tried to run the code with my own images, I posted my images here but I'm just not sure how to solve this, can someone help? <img width="1440" alt="Screen Shot 2021-09-17 at 11 19 17 AM" src="https://user-images.githubusercontent.com/33333641/133808013-e61d9217-4c78-47b8-9292-befa276b09df.png" Screen Shot 2021-09-17 at 11 19 11 AM Screen Shot 2021-09-17 at 11 19 05 AM Screen Shot 2021-09-17 at 11 19 04 AM Screen Shot 2021-09-17 at 11 18 58 AM

    help wanted 
    opened by awesomekid1021 4
  • Simple script to generate the config.json!

    Simple script to generate the config.json!

    File should be placed in the main directory, the script will then scrape all the files in ./trait-layers to generate a baseline config with balanced rarities.

    opened by whosman 3
  • Weights for layer groups

    Weights for layer groups

    Would be great to add support for weights for layer groups. Lets say we have following layer groups:

    Background - always render Body - always render Head - always render Hats - render only on 20% of images Glasses - render only on 10% of images

    btw. love your script, really nicely done.

    enhancement 
    opened by mwkemo 3
Releases(v2.0.0)
  • v2.0.0(May 2, 2022)

    What's Changed

    • [#17] Adding requirements file by @elyak123 in https://github.com/Jon-Becker/nft-generator-py/pull/18
    • fixed an issue which uses a wrong variable name by @AlexLisong in https://github.com/Jon-Becker/nft-generator-py/pull/22
    • Substitute convert('RGB') for convert('RGBA') by @menezesphill in https://github.com/Jon-Becker/nft-generator-py/pull/33

    New Contributors

    • @elyak123 made their first contribution in https://github.com/Jon-Becker/nft-generator-py/pull/18
    • @AlexLisong made their first contribution in https://github.com/Jon-Becker/nft-generator-py/pull/22
    • @menezesphill made their first contribution in https://github.com/Jon-Becker/nft-generator-py/pull/33

    Full Changelog: https://github.com/Jon-Becker/nft-generator-py/compare/v1.0.2...v2.0.0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.2-beta1(Mar 18, 2022)

  • v1.0.2(Nov 8, 2021)

  • v1.0.1(Nov 2, 2021)

  • stable(Sep 1, 2021)

Owner
Jonathan Becker
Developer & Designer
Jonathan Becker
Ascify-Art - An easy to use, GUI based and user-friendly colored ASCII art generator from images!

Ascify-Art This is a python based colored ASCII art generator for free! How to Install? You can download and use the python version if you want, modul

Akash Bora 14 Dec 31, 2022
Vignette is a Python library to create and manage thumbnails following the FreeDesktop standard.

Vignette Vignette is a Python library to create and manage thumbnails following the FreeDesktop standard. Thumbnails are stored in a shared directory

3 Feb 06, 2022
DrawBot is a powerful, free application for macOS that invites you to write Python scripts to generate two-dimensional graphics

DrawBot is a powerful, free application for macOS that invites you to write Python scripts to generate two-dimensional graphics.

Frederik Berlaen 344 Jan 06, 2023
Tools for making image cutouts from sets of TESS full frame images

Cutout tools for astronomical images Astrocut provides tools for making cutouts from sets of astronomical images with shared footprints. It is under a

Space Telescope Science Institute 20 Dec 16, 2022
A simple Streamlit Component to compare images in Streamlit apps. It integrates Knightlab's JuxtaposeJS

streamlit-image-juxtapose A simple Streamlit Component to compare images in Streamlit apps using Knightlab's JuxtaposeJS. The images are saved to the

Robin 30 Dec 31, 2022
Converting Images Into Minecraft Houses

Converting Images Into Minecraft Houses In this particular project, we turned a 2D Image into Minecraft pixel art and then scaled it in 3D such that i

Mathias Oliver Valdbjørn Jørgensen 1 Feb 02, 2022
BeeRef — A Simple Reference Image Viewer

BeeRef — A Simple Reference Image Viewer BeeRef lets you quickly arrange your reference images and view them while you create. Its minimal interface i

Rebecca 245 Dec 25, 2022
DP2 graph edit codes.

必要なソフト・パッケージ Python3 Numpy JSON Matplotlib 動作確認環境 MacBook Air M1 Python 3.8.2 (arm64) Numpy 1.22.0 Matplotlib 3.5.1 JSON 2.0.9 使い方 draw_time_histgram(

1 Feb 19, 2022
Tweet2Image - Convert tweets to Instagram-friendly images.

Convert tweets to Instagram-friendly images. How to use If you want to use this repository as a submodule, don't forget to put the fonts d

Janu Lingeswaran 1 Mar 11, 2022
This will help to read QR codes using Raspberry Pi and Pi Camera

Raspberry-Pi-Generate-and-Read-QR-code This will help to read QR codes using Raspberry Pi and Pi Camera Install the required libraries first in your T

Raspberry_Pi Pakistan 2 Nov 06, 2021
PyLibTiff - a wrapper to the libtiff library to Python using ctypes

PyLibTiff is a package that provides: a wrapper to the libtiff library to Python using ctypes. a pure Python module for reading and writing TIFF and L

Pearu Peterson 105 Dec 21, 2022
Easily turn large sets of image urls to an image dataset. Can download, resize and package 100M urls in 20h on one machine.

img2dataset Easily turn large sets of image urls to an image dataset. Can download, resize and package 100M urls in 20h on one machine. Also supports

Romain Beaumont 1.4k Jan 01, 2023
MaryJane is a simple MJPEG server written in Python.

MaryJane is a simple MJPEG server written in Python.

bootrino 152 Dec 13, 2022
Qrgenerator - A qr generator app using python3

qrgenerator by Mal4D Hi welcome into qr code generator using python by Mal4d Lin

Mal4D 1 Jan 09, 2022
Pnuemonia Normal detection by using XRay images.

Pnuemonia Normal detection by using XRay images. Got image datas from kaggle(link is given in sources.txt file) also normal xray images from other site (also link is given) in order to avoid data dis

Zarina 1 Feb 28, 2022
Alternate Python bindings for the Open Asset Import Library (ASSIMP)

Impasse A simple Python wrapper for assimp using cffi to access the library. Requires Python = 3.7. It's a fork of PyAssimp, Assimp's official Python

Salad Dais 3 Sep 26, 2022
A tool for making simple-style text posters or wallpapers with high resolution.

PurePoster PurePoster is a fancy tool for making arbitrary-resolution, simple-style posters or wallpapers with text in center. Functionality PurePoste

Renyang Guan 4 Jul 09, 2022
Python binding to Skia Graphics Library

Skia python binding Python binding to Skia Graphics Library. Binding based on pybind11. Currently, the binding is under active development. Install Bi

Kota Yamaguchi 170 Jan 06, 2023
The coolest python qrcode maker for small businesses.

QR.ify The coolest python qrcode maker for small businesses. Author Zach Yusuf Project description Python final project. Built to test python skills P

zachystuff 2 Jan 14, 2022
Tool to create a Phunk image with a custom background

Create Phunk image Tool to create a Phunk image with a custom background Installation Clone the repo git clone https://github.com/albanow/etherscan_sa

Albano Pena Torres 6 Mar 31, 2022