Generate 500+ NFTs using Python PIL

I’m a visual learner, so it’s beneficial for me to see things in action and not just in lines of code. That’s why I came up with a quick little exercise to knock the dust off my python skills as well as help me generate test NFTs quickly. I used python to rapidly generate 500+ images from a list of hexadecimal values of colors. With Python Imaging Library (PIL), there’s no limit to how much you can quickly generate if you need to. Let’s get started!

For this tutorial, I’m going to assume you have python already installed. Now install Pillow.

Note: You may have to try pip3 instead. Next, get a list of hexadecimal colors and save them to a .txt file. I found mine here.

Next, start a new .py file and begin it like this:

Next, read the .txt file you made:

Check to see if the data looks right:

If you used the list from the site I linked to, then you will have to strip the extra newlines (‘\n’). We do this with the strip() function, placed inside a good ol’ for-in loop. Next, you have to nest another for-in loop to create a new Image for each. Set the mode, size, and color as seen below. Then, save that image to the colors folder.

Perfect! We’ve got 500+ test images to test our NFT contracts against. Maybe I should go try to sell this collection :P



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store

Law, programming, and everything in-between! Coming up with fun coding projects with real-world application.