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
Image Reading, Metadata Conversion, and Image Writing for Microscopy Images in Python

AICSImageIO Image Reading, Metadata Conversion, and Image Writing for Microscopy Images in Pure Python Features Supports reading metadata and imaging

Allen Institute for Cell Science - Modeling 137 Dec 14, 2022
A python based library to help you create unique generative images based on Rarity for your next NFT Project

Generative-NFT Generate Unique Images based on Rarity A python based library to help you create unique generative images based on Rarity for your next

Kartikay Bhutani 8 Sep 21, 2022
Easy to use Python module to extract Exif metadata from digital image files.

Easy to use Python module to extract Exif metadata from digital image files.

ianaré sévi 719 Jan 5, 2023
A utility for quickly cropping large collections of images.

Crop Tool A utility for quickly cropping large collections of images. Inspired by Derrick Schultz's dataset-tools. Setup It's suggested that you use A

dusk (they/them) 6 Nov 14, 2021
Photini - A free, easy to use, digital photograph metadata (Exif, IPTC, XMP) editing application for Linux, Windows and MacOS.

A free, easy to use, digital photograph metadata (Exif, IPTC, XMP) editing application for Linux, Windows and MacOS. "Metadata" is said to mea

Jim Easterbrook 120 Dec 20, 2022
MetaStalk is a tool that can be used to generate graphs from the metadata of JPEG, TIFF, and HEIC images

MetaStalk About MetaStalk is a tool that can be used to generate graphs from the metadata of JPEG, TIFF, and HEIC images, which are tested. More forma

Cyb3r Jak3 1 Jul 5, 2021
Next-generation of the non-destructive, node-based 2D image graphics editor

Non-destructive, node-based 2D image graphics editor written in Python, focused on simplicity, speed, elegance, and usability

Gimel Studio 238 Dec 30, 2022
Image generation API.

Image Generator API This is an api im working on Currently its just a test project Im trying to make custom readme images with your discord account pr

Siddhesh Zantye 2 Feb 19, 2022
Anaglyph 3D Converter - A python script that adds a 3D anaglyph style effect to an image using the Pillow image processing package.

Anaglyph 3D Converter - A python script that adds a 3D anaglyph style effect to an image using the Pillow image processing package.

Kizdude 2 Jan 22, 2022
Simple Python package to convert an image into a quantized image using a customizable palette

Simple Python package to convert an image into a quantized image using a customizable palette. Resulting image can be displayed by ePaper displays such as Waveshare displays.

Luis Obis 3 Apr 13, 2022
An open source image editor which can manipulate an image in many ways!

Image Editor - An open source image editor which can manipulate an image in many ways! If you need any more modes in repo or I

TroJanzHEX 44 Nov 17, 2022
Image enhancing model for making a blurred image to be somehow clearer than before

This is a very small prject which helps in enhancing the images by taking a Input images. This project has many features like detcting the faces and enhaning the faces itself and also a feature which enhances the whole image

null 3 Dec 3, 2021
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 1, 2023
Nanosensor Image Processor (NanoImgPro), a python-based image analysis tool for dopamine nanosensors

NanoImgPro Nanosensor Image Processor (NanoImgPro), a python-based image analysis tool for dopamine nanosensors NanoImgPro.py contains the main class

null 1 Mar 2, 2022
A pure python implementation of the GIMP XCF image format. Use this to interact with GIMP image formats

Pure Python implementation of the GIMP image formats (.xcf projects as well as brushes, patterns, etc)

FHPyhtonUtils 8 Dec 30, 2022
Image-Viewer is a Windows image viewer based on Python 3.

Image-Viewer Hi! Image-Viewer is a Windows image viewer based on Python 3. Using You must download Image-Viewer.exe from the root of the repository. T

null 2 Apr 18, 2022
Seaborn-image is a Python image visualization library based on matplotlib and provides a high-level API to draw attractive and informative images quickly and effectively.

seaborn-image: image data visualization Description Seaborn-image is a Python image visualization library based on matplotlib and provides a high-leve

null 48 Jan 5, 2023
This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specialized data structure called VP-Tree which makes searching an image on a dataset of 100Ks almost instantanious

Offline Reverse Image Search Overview This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specia

null 53 Nov 15, 2022
Quickly 'anonymize' all people in an image. This script will put a black bar over all eye-pairs in an image

Face-Detacher Quickly 'anonymize' all people in an image. This script will put a black bar over all eye-pairs in an image This is a small python scrip

Don Cato 1 Oct 29, 2021