Create NFT Generative Art with Python! (Full Tutorial)
Вставка
- Опубліковано 19 чер 2024
- In this project, we'll be creating a Python program to generate artwork for an NFT collection from scratch (in about 45 minutes, starting from a completely empty project).
To follow along, you'll need to know some basic Python, and know how to install packages (e.g. using `pip install`).
00:00 Introduction
01:33 What is generative art?
02:03 Prerequisites
02:40 Start from empty project
04:10 Create new image
07:07 Drawing lines
11:50 Connecting the lines
16:40 Adding thickness
18:13 Adding color
23:45 Centering the image
32:30 Adding color channels
38:30 Picking brighter colors
43:09 Anti-alias
47:49 Wrap-up
👉 Tutorial Source: github.com/pixegami/python-ge...
👉 Original Project Gallery: www.mach-psy.com/
👉 Original Project Source: github.com/pixegami-team/mach...
👉 Python PILLOW library: pillow.readthedocs.io/en/stable/
Although I'm familiar with Python, your method of pedagogy is just fabulous and it is seriously criminal that you neither have the views nor the subscribers that you actually deserve. But I do see a great future for this channel and I will be a silent cheerleader for your channel's success 🙌 👍
Thank you! I really appreciate hearing that feedback. Also - I had to look up what "pedagogy" means (for anyone who doesn't know, it's "the method and practice of teaching").
Ll
Agreed! I also like that I learned a new word today. Pedagogy!
This Generative Art video was so much fun to watch. Please consider doing more videos like this.
Thank you so much for the tip and the comments 🙏 I really appreciate it, and I'm glad you enjoyed the video :)
I'm only half way thru the video and I'm loving it. I hope it doesn't end.
Wow... in a only shot, I learned more than a tons of tutorial I watched. Very useful! Thanks a lot!
I'm glad it helped! I appreciate the feedback!
Nice video!! Just started with python a few days ago but i managed to follow you in every way ! :)
I didn't overlook how skillfully you defined if __name__ == '__main'. You wouldn't (maybe you would) believe how many tutorials and articles fail to execute on this definition effectively and succinctly. Nice tangential value add!
Ah thanks for the comment :) I never know if it’s worthwhile to go on that kind of tangent, so I appreciate the feedback.
@Pixegami this is amazing. Many thanks to you!
Awesome work dude!
Great work, thank you for sharing!
Very good illustration
Nice Guide! Thank you :) Maybe more with other art or ideas :)
Masterpiece, and it is seriously criminal that you neither have the views nor the subscribers that you actually deserve But best of luck for the future.
we need more videos about generating NFTs from base characters by python coding ..please...please.Love from PAKISTAN
I would have loved to see the gpt3, react, and especially erc 721 sections too!!! Great video sir!!!!
Thank you and noted! I will probably do a technical deep dive video on what I learn about NFTs as well so maybe that would fit in there. For GPT-3 stuff, I have another video that explores the API a bit more (using poetry and creative writing: ua-cam.com/video/r3zKcL0iGeA/v-deo.html)
MY MANN YOURE A LEGEND
Fantastic tutorial dude! Thank you!!!
Glad you liked it!
Great video, thanks!
Thanks for great job and amazing digitall art.
Fantastic video! Thank you for sharing. I’ve happily subscribed. It’s only fair. You taught me for free :)
Very cool video. Thanks
Thank you so much for this 🔥🍻
You're a real Pro! Congratulations and keep going sharing your wisdom! The more you share the wiser you'll become.
That's the plan!
Good work. thanks
Damnn man, I learned so much from this single tutorial.
Love from Banglore India
I'm glad to hear that!
For anyone doing it using the most up to date PIL version you'll need to change the resize and antialias line to something like this
image = image.resize((target_size_px, target_size_px), Image.ANTIALIAS)
Great content BTW!!!
image = image.resize((target_size_px, target_size_px), Image.LANCZOS)
Great tutorial!!! Would love to see more from you
More to come!
Dude! You're a #Legend 👑 for this! 🚀✨👍
Great, thanks 🇲🇽
I see a future 100k UA-camr here
Thanks for the encouragement :)
same here
He’s very good, he’s a skilled programmer but also his delivery in explaining is spot on. Very rare to get both.
very nice video! keep going :)
this is amazing! Thank you! Can we please get a tutorial on how to really create NFT 's? Thank you in advance
is a pleasure watch you program! I understand a little bit of python, my head explodes but is like watching you do art! thank you!, can you make a video showing how to use OpenAI GPT-3 To name the files? thanks
Thank you! I plan to do more art-coding videos soon. I have two other videos on Open AI (one is a generic exploration of its ability, the other one "Build an AI-driven SaaS" actually shows more hands-on how to use Open AI. The way I used it to generate names isn't too different from what I did in that latter video.
1 k soon keep it up bro
Great video
Thanks!
You deserve a million subs, Vegemite bro
Man you earn new subscriber.
Awesome, thank you!
I think honestly that this is one of the best tutorial videos I ever saw.👏👏👏
Is it possible to generate multiple nft arts from one existing picture?
Thanks! As for your question - do you mean like have an image be used to generate a variety of different images? Or use one image and publish it as several different NFT tokens? Either way, both are possible. But what would your intention be behind this?
@@pixegami use one image to create multiple nft's..
yess thank you
This is amazing , can you make another video explaining how to upload all NFTS to OpenSea and put them price. Please !
Good content
👍
Best NFT tutorial out there.
Recommendation:
If possible will you also start programming tutorial too 💯
Thanks :)
Thanks 🤠🙏
Hasta yo lo entendí y no sé inglés wtf eres muy bueno! estoy empezando en Python y no manejo ni 1% de ello pero tú lo haces muy fácil quiero ser como tú ☺️
That's amazing! I can't read Spanish so I used Google translate to read your message. Thank you, I'm glad the video made sense for you and I look forward to sharing more awesome stuff in the future.
merci bro, it work with me
but i had problem in saving image, so i use function "show" to see image.
Thanks for the tutorial. You're a great coder! I'm learning python and I still code slowly, how do you do this so seamlessly?
I didn't do anything special to be able to code 'seamlessly' (actually I still get stuck and make lots of mistakes). I think it just comes with time. Just focus on the problem or want to solve, or the idea you want to build, and don't worry whether you code fast or slow.
Also, for these tutorials, I usually prototype the whole idea first before I start recording. So when I'm recording it, I already know which direction I'm going to go. If I do actual live-stream of me coding, you'll see me pause and go back-and-forth a whole lot more.
@@pixegami Understood. I started coding about 6 months ago and I guess it does get a little bit easier overtime, there's just so much to learn that it can feel overwhelming. Have your NFT's found some buyers, or were you just doing this as sort of a project?
First time using python, let's see if i can follow till the end! :D
Hey, i subscribe you to boot your confidence please not give up, continue your Hutsle one day you have millions 9f subscribers, God bless you .
I'd like to add a random background color to this code, so could you tell me how to do it?
What editor are you using? I love that you get the png preview right there.
Yes, you find out which editor he's using,
Oh ok, VSCode
Yup, this is just VSCode (available for free) without any plugins. VSCode can render images, so I just made that a separate window, and it refreshes when the image changes.
@@pixegami I love it. My new favorite editor, and thank you for this awesome tutorial!
I m getting an error saying there is no module name PIL. Even I have installed pillow. What should I do
First a big thanks for this tutorial! I've actually been inspired by your work here and had a go head-first into the NFT world with a similar code!
But do have question @line 100 in your GH code: "next_point = points[i + 1]" - could possibly explain the technicality behind this iteration? I do understand what it does :) but not HOW it does it... cause if you print out "i" you'd get the correct iteration number w/ the next iteration's value...
Later Edit: you can disregard the question if you want, got it! :)
I’m not 100% sure if this was the question you are asking, but I’ll talk about it anyway in case others have the same question. So the “i+1” part of the iteration is to get the ‘next’ point in that list. In order to draw a line, we need two points. So to join a list of points together, we join points n and n+1.
how can i export my programming to SVG. to open in grbl plotter ? need help :/
Question:
I've followed this tutorial up to 11:38 step by step.
But there is one issue, every time i keep running the program, it doesn;t draw the line at all, even if I mess with the "image_bg_color" variable it wont change the picture, it continues to save a blank image.
Am i doing something wrong? or is it something else that im overlooking?
Alright, so after some testing, turns out that its not saving a new image, it keeps the old archive, hence why its only showing a white square.
Now the question is, the program doesn't show any problem and it "runs" with no compilation issues, but it's not overwriting the previous archive in order to show the new one...
NVM , managed to get through the tutorial andget the finishing results.
Glad you found the solution :) Yeah, image software can be a little fidgety to debug and test, so well done for persevering and getting the results.
I love your keyboard
Thanks! It's a K2 Keychron wireless compact. It looks nice on the desk but I actually prefer a larger layout. The keys are MX-Cherry Red. They're OK to type with. Personally I think blue-switches are the most satisfying, but it's probably too loud for the video (and for my house mates).
The pip doesn't work on my MacBook, I have installed few ways but still doesn't work and also my python version says 2.7 on the vscode even though I have installed 3.9 from the python website, any help would be appreciated.
Ah ok, it looks like you need to first spend a bit of time understanding and setting up virtual environments in Python. The reason `pip` doesn't work for you isn't because you are on MacOS, but because you are the OS's system version of Python.
When we work on projects, we don't want to use or modify the system Python (that's for the OS to use). We need to download and setup our own version and environment for it. That's how you can get 3.9 and pip. Here's more on virtual environments: docs.python.org/3/library/venv.html
Also, when you use Python in VSCode, you can choose *which* Python environment you are using. It sounds like by default it's chosen your system Python 2.7, but ignored you newly installed 3.9. You can change it to use that instead. Check here: code.visualstudio.com/docs/python/environments
what keyboard is this? Sounds amazing.
This is a K2 Keychron with red cherry MX switches.
hello sir,
which python interface are you using like pycharm, anaconda, normal python etc.
I use VSCode as my IDE (I also use PyCharm for bigger projects, but these days VSCode is good enough).
I don't use Anaconda, but I do sometimes use conda (with pip) as a package manager.
@@pixegami ok sir thank you
You are great ☺️ ooo man
Thank you so much 😀
You best
Could you show us how to layer image files that are stored in a directory?
Ah yeah I know what you’re talking about. That could be a fun video, I’ll give it a shot.
Have you ever done a video on using parameter hints? As a new programmer, this is one of the things that I find very frustrating. I know there's good information in the popup, but I don't know how to use it effectively.
Yup, I have one on dataclasses (using type-hints): ua-cam.com/video/9B9CdKANjnM/v-deo.html and one using Pydantic as well: ua-cam.com/video/XIdQ6gO3Anc/v-deo.html
watching you coding... its beautiful
Good tutorial for learning python and indeed image drawing/manipulation in python but I'd loose the NFT from the title because this doesn't cover anything about how to make NFTs... only images.
That's a good suggestion - but the actual project code does have an NFT deployment contract included.
It just wasn't used or covered because ETH gas fees were really expensive :( I kept the title because I think it helps people with the intent to generate NFT art discover this more easily.
Can anyone please explains to me how the part that connects all the dots works? I have tried to understand all the functions but cant seem to figure it out.
If we have a list of dots (x, y), then we can use the PIL draw.line() method to draw lines between the points. I suggest reading the doc and trying it out with a smaller set of points first to get a better understanding: pillow.readthedocs.io/en/stable/reference/ImageDraw.html#PIL.ImageDraw.ImageDraw.line
@@pixegami Thank you very much!
What program u use sir?
VSCode as my IDE. For terminal, it’s just the regular Ubuntu terminal app, using zshell as the shell, and OhMyZsh plugin with a modified Agnoster theme.
where i can contact you ?
is the code for this somewhere?
i looked at the githubs and could not find it
Here is the full version: github.com/pixegami-team/machine-psychology-python-art
Here is the one I used in the tutorial: github.com/pixegami/python-generative-art-tutorial
Hey thanks for the great vid. i kept following u to 15:11 when i write p2=[i+1] it says index out of range anyone knows how to solve it?
This usually means that your list doesn't have an element at index "i+1". To debug, you can use a breakpoint to check what the contents of that list are (look up how to use breakpoints in Python). Or simpler, just print the list out before you try to access that index (for a more brute force approach).
@@pixegami okay i ll see to it thanks!
Will this work with blender and 3d art?
Not really. I don’t know how blender works yet so I’ll have to find out first.
@@pixegami did you find a way to make it possible on blender?
Is it possible to make on a 3D blender character?
I don’t even know how to use Blender, so I can’t make a tutorial about it yet - but from what I know about modelling and coding in general, I’m 100% sure it is possible.
What a day we're living in where Keanu Reeves is teaching us programming
Thank you for this!! but can anyone help me with this? I get an error when I run it:
Exception has occurred: TypeError
join() argument must be str, bytes, or os.PathLike object, not 'NoneType'
During handling of the above exception, another exception occurred:
File "C:\Users\Home\Downloads\python-generative-art-tutorial-main\src\generate_art.py", line 42, in generate_art
output_dir = os.path.join('output', collection)
File "C:\Users\Home\Downloads\python-generative-art-tutorial-main\src\generate_art.py", line 135, in
generate_art(collection_name, f"{collection_name}_image_{i}")
yeah i get the same error....any advice please?? TIA
@@kryptoknight742 Heyy, I think I have found the solution because now it runs successfully. But I forgot what line the error is in. Can you tell me the line of code that gets you an error?
@@gemcapistrano same as yours mate. I strayed from scratch and it relates to the batch editing. So I’m just doing 1 at a time haha. Changing the name in the script. Easy enough 👍🏻
It’s hard to debug an error without seeing the full stack-trace or code, but the error message “Exception has occurred … NoneType” tells me that one of the values you are passing is `None` to os.path.join(). My debug approach would be to check each of the values I’m about to pass in and see which is `None`.
cute
What is the avantages to use python for create NFT instead of Opensea ? Thanks
Python is just for generating the images. OpenSea is for uploading them (or using as a marketplace) - so the two technologies aren’t mutually exclusive.
i only have one question: it says module named PIL not found
This is because you need to install "pillow" (the Python imaging library) into your environment. If you think you've already installed it, but still get the error - it means the place you installed it is different to the place you are running this script.
You can read more about that if you just search Google for something like "managing packages in Python" or "setting up an environment in Python."
What happened to the naming part?
Oh dear, did I forget to include that? I have another video where I actually use GPT-3 in more detail, so you can get a sense of the technology and API there: ua-cam.com/video/yxyyYMWu1ZA/v-deo.html (see the chapter about Open AI).
And though not covered in the tutorial, my full project is also available on GitHub. The naming script is there: github.com/pixegami-team/machine-psychology-python-art/blob/main/src/art_name_generator.py
Will this work for 3d collection
If you mean 3D art, it's also just a data file at the end of the day, so you can probably write a Python program to generate 3D models and textures. But this tutorial specifically won't really give you useful information on how to do that (maybe unless you adapt the points to 3D space and plug it into a modelling/rendering tool).
Is python free? :-)
Yup
@@vincentkarlsson4481 🙏😊
Absolutely. All the tools used in the video are free for all platforms.
nice lovely video, you also cute
this word, art; I'm not sure it means what you think it means.
Ah well, gotta start somewhere 😬
Sub indo plss 🥲
congrats, you managed to automate "art"
(this is a bad thing)
why?
Haha, well…Technically this is just automating image generation. “Art” itself is probably in the perspective of the viewer, and I don’t know if that can ever be automated.
Programming itself should be considered an art, if you ask me....
this is art
NFTs? No fucking thanks.
😬 It's a popular subject so I thought I'd look into it. But honestly I'm struggling to find useful projects or tutorials to do with it
Great video, thanks!