Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script for nft gen #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions file-bunnies/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.png
14 changes: 14 additions & 0 deletions file-bunnies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# A script to generate File-Bunnies NFTs.

Script assumes that all NFT parts is having the same resolution and/or pivot point in (0, 0).

optional arguments:
-h, --help show this help message and exit
--src Path to the directory with NFT parts.
--dst Path to the destination directory.

```
python3 gen-bunnies.py \
--src /home/batman/Documents/work/file-bunnies/parts \
--dst /home/batman/Documents/work/file-bunnies/NFTs
```
76 changes: 76 additions & 0 deletions file-bunnies/gen-bunnies.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gopher-powerful

Извинись

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import os
import argparse
from concurrent.futures import ThreadPoolExecutor
import logging
from itertools import product
from PIL import Image

WIDTH = 2048
HEIGHT = 2048

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

parser = argparse.ArgumentParser(description="A script to generate File-Bunnies NFTs. Script assumes that all parts is equal sized.")
parser.add_argument('--src', type=str, required=True, help='Path to the directory with NFT parts.')
parser.add_argument('--dst', type=str, required=True, help='Path to the destination directory.')
args = parser.parse_args()


def process_image(parts, count, dstpath):
bg, boots, bunnie, fc, glasses, pet = parts

new_image = Image.new('RGBA', (WIDTH, HEIGHT))

bg_img = Image.open(bg).convert("RGBA")
bunnie_img = Image.open(bunnie).convert("RGBA")
boots_img = Image.open(boots).convert("RGBA")
glasses_img = Image.open(glasses).convert("RGBA")
fc_img = Image.open(fc).convert("RGBA")
pet_img = Image.open(pet).convert("RGBA")

new_image = Image.alpha_composite(new_image, bg_img)
new_image = Image.alpha_composite(new_image, bunnie_img)
new_image = Image.alpha_composite(new_image, boots_img)
new_image = Image.alpha_composite(new_image, glasses_img)
new_image = Image.alpha_composite(new_image, fc_img)
new_image = Image.alpha_composite(new_image, pet_img)

# TODO: Save to separate dir, gen metadata, gen aes key etc.
new_image.save(f"{dstpath}{count}.png")
logging.info(f"Processed combination #{count}.")


def main():
parts_path = os.path.abspath(os.path.normpath(args.src)) + os.path.sep
dst_path = os.path.abspath(os.path.normpath(args.dst)) + os.path.sep

os.chdir(parts_path)

background_files = [parts_path + 'background/' + f for f in os.listdir('background/') if f.endswith(".png")]
boots_files = [parts_path + 'boots/' + f for f in os.listdir('boots/') if f.endswith(".png")]
bunnies_files = [parts_path + 'bunnies/' + f for f in os.listdir('bunnies/') if f.endswith(".png")]
filecoin_files = [parts_path + 'filecoin for the body/' + f for f in os.listdir('filecoin for the body/') if f.endswith(".png")]
glasses_files = [parts_path + 'glasses/' + f for f in os.listdir('glasses/') if f.endswith(".png")]
pets_files = [parts_path + 'pets/' + f for f in os.listdir('pets/') if f.endswith(".png")]

try:
os.mkdir(dst_path)
except OSError as error:
pass

os.chdir(dst_path)

num_combos = len(background_files) * len(boots_files) * len(bunnies_files) * len(filecoin_files) * len(glasses_files) * len(pets_files)
logging.info(f"Started processing {num_combos} NFTs...")

count = 0
with ThreadPoolExecutor() as executor:
for parts in product(background_files, boots_files, bunnies_files, filecoin_files, glasses_files, pets_files):
executor.submit(process_image, parts, count, dst_path)
count += 1

logging.info(f"Finished processing {count} images in {num_combos} combinations.")


if __name__ == "__main__":
main()
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.