 So if you watched my last video, you're probably wondering, Chris, why would I ever, ever do that? Why would I ever convert an image into text and back again? And although I did give some examples in there, today we're going to do it again in another very inefficient way to do something. We are going to use that command. We're going to use image magic to convert an image into text. And then we're going to use some command line tools to take that and convert that text into a Python script, which we can then paste into Blender to generate an object. Very completely inefficient way to do this. What I'm doing could probably be done with Python alone in Blender. But I'm using my knowledge on what I know how to do to accomplish something. Now, if you go way back in my videos, a long time ago, I made a video where I basically took an image of Mario from the Super Mario Brothers, old 8-bit pixels. And I made a cube for each pixel. And I by hand lined them up and colored them. So then I had a grid, if you will, of cubes that shaped Mario and their colors. And I did that by hand. I'll probably have, if I can find it, the video up on screen right now, which was fun. But why do that when I can automate it? Or at least mostly automate it. I should be able to fully automate it again with Python in Blender. But I am going to use Bash, because that's what I'm most familiar with, to generate Python script that I'm going to paste into Blender. Completely very inefficient. But it works. It works. And again, it's just for fun. I'm going to show you how it runs. And basically, yeah, I'll just show you. OK, here we are. I'm in a directory where I have a couple of sprites and my script. And then I also have Blender open here. Let's get Blender ready to go. I'm running Blender 3.64 right now. But this should work with pretty much every version of Blender that's out currently. I'm going to split the screen horizontally here. I'm going to change this top box, this top view, into a Python console. Now, in here, you can type in Python code. Anything you can think of doing in Blender, you can do by typing code. So if you want to create objects, manipulate objects, create materials, apply those materials, change the materials, you can do all that. Just whatever you can imagine, you can write Python scripts. And you can actually import Python scripts. And you can make modules and plugins with Python scripts. We're just going to paste code directly into here. And when my shell script does, again, it's going to take the image, convert the image into text where each line has a coordinate and a color value for that pixel. And it's going to then create Python code that will create a cube or a box. Based on that, it's going to create it and place it in its location. Then it's going to create a material of the proper color and then apply that color. Again, it's not very efficient because it's going to create a new material for each one of these pixels in the image, even if that color already exists as a material. But again, this is just for fun. I'm sure there's going to be some issues. I can already predict one because when you use image magic to convert an image to text, it gives you a RGB value. But if it's a perfect black or white, it's just going to say black or white. And my code has already converted. If it's a pure black or pure white, it will convert it to the proper RGB values. But if you have a color that is a perfect red or a perfect blue or a perfect green, it will say red, blue or green. And my code currently doesn't adjust that because it's got to be pixel perfect of that color. If it's one value off, it won't say that. So it's not that big of a deal. But let's go ahead. I'm going to delete everything in this director or in this view. I am going to go back to my shell here. I am going to run my command. Now, if I just run my script, which again will be linked in the description of this video, it's going to start printing all the Python code to the screen. And I don't want that. What I want to do is I want to put it into my clipboard. I'm going to use X clip. X clip may not be installed by default. There's also X selection. There's other ways to get into a clipboard. You can always put in a file and then copy that file. Here we go. I just put it in there. So just install X clip if you haven't. And I am then going to go back to blender. I'm going to make sure I'm in my mouse cursor is over this console window. And I'm going to hit control V and enter. And I'm going to wait. Cause it's going to paste again, three lines for every pixel. So it takes a moment. And there we go. I have my Mario here. Let's go ahead and go to a rendered preview. And that's what he looks like. Now you may notice if we go back to here, he's actually flipped the reverse way as he is in the image. If that's an issue for you, what you can do is control A to select them all, R to rotate, Y 90, or actually 180 is what we want. And now he's facing the other way. So again, each one of these is its own little cube for every single pixel. So again, you do not want to use large images. This Mario is 16 pixels tall and I think like 12 wide. In fact, let's go into GIMP now where I have a couple of these images open. This one's rather large. I wanna say it's, let's see. It's, I think it's about 58 pixels tall or no. I think it's 64 pixels tall and then 70 some wide. So that's a rather large image. Now, a few things to take note. Again, resize it down. Make sure it's not a large image. Otherwise you are going to get a lot of blocks and it's probably gonna freeze up your machine. I'm using little images here. Cropped away all the excess stuff. Now, also make sure, so look at this Mario. If I go up to image and I go to mode, you can see this one's indexed. You wanna set that to RGB before you export it as a PNG. And you do want it to be a PNG because you want this, well, in most cases, want this transparent background, which my script does take into account. Now, if you don't do that, if you leave it as indexed, it will generate Mario, but its colors will be all weird because index, it's using this palette and we don't have that palette when we're converting it over into Blender. But let's go ahead and try this with a few other examples here. I will now go with, we'll do my Goomba here. Again, just wait a second for that to all be pasted into the clipboard there. I will go into Blender. I'm going to move Mario over here. Go over there, Mario. Again, make sure that your cursor is over your console here. Control V and hit Enter and then wait. Again, it's running three lines of code for each pixel. So we're talking easily 1,000 lines of code here. I hope it pasted it. Oh, there we go, just took a second. There we go. So now we've got our Goomba. I'm going to select all, whoop, not hide. Let's, can we unhide? Oh well, I'd forget what key unhide stuff. Anyway, those are hidden now. Can I unhide? No, it doesn't work like that. Anyway, not a big deal. We'll run it again. Again, we will do it with one of our turtles. Turtle 1 PNG. And I will paste that into here. While that's pasting, I will then do Bowser PNG. Back to, where's, oh, it's not showing up because it's locked until it's done pasting. Let's go ahead and just pause the recording here for a second. There we go. Took a moment. There's our turtle. It almost looks like he's got transparency there, but that's just the white looking like gray and the other lighting. So this is a texture preview. This is rendered and I have no lighting. Let's go ahead and paste in our Bowser. And oh, I should have moved this turtle first. They're going to overlap. I will pause for a moment. Again, it doesn't take too long. Bowser's a little bit bigger. So I'm going to assume maybe 30 seconds or so and he'll be done. And your mileage may vary based on your computer. My computer is not the fastest in the world. And again, I'm pasting into here. Theoretically, you could put this into a Python file and import that and it probably would run faster. And also my screen recorder tends to bog down my machine. I did do test runs of this when I wasn't recording and it did go a whole lot faster while that's still working on that. Let's go ahead and run that again. But instead of copying it to our clipboard, let's go ahead and count the number of lines. And so we can see exactly how many lines of code we are pasting into Blender. Even this has taken a moment. So yeah, we're pasting 3,186 lines of code into Blender right now. Here we go, he's in there. And again, I forgot to move the turtle before we did that. So they're kind of overlapped. And since every cube is an individual object, separating them is not gonna happen. It's kind of like what happens in time cop when the same material occupies the same space at the same time, if you know what I mean. Anyway, yeah, so I will link to my script that you get this from. If you can improve upon it, that'd be great. If you could run a Python straight code, even better for Blender. Real quick, I can even show you my script. Again, it is not beautiful. And this is just for fun. And let's go ahead and make this full screen. So yeah, it's checking for input. If not, it's gonna exit. Then it's gonna check, does that file exist? If not, it's gonna exit. Then we're gonna use the convert command from image magic to take the image that was passed, convert it to text. Then we're going to remove, basically I could just remove the top line by removing any line that starts with a pound symbol, because that's the top line's comment. And then we're going to print the first and fourth column. And then I am going to remove where it says s-r-g-b-a forward slash, and I'm gonna just replace that with a comma. And then I'm going to remove the final parentheses there. That will give us most of what we need. But then again, if it's a pure black or pure white, it's going to say black or white. What I'm doing here is replacing black with 0, 0, 0 as a value, white with 255, 255, 255. Blender does not want a value from 0 to 255. It wants a value from 0 to 1. So then I'm going to use b-c here to convert that. I'm gonna divide this number by 255, which will give me that decimal number we need. We want at least six decimal points long. So that's what the scale six is. We're also saying if the line says none, that would be a transparent pixel. We're just going to skip that. So at that point, after we do all this conversion, we will get the color, which is r-g-b. I am then gonna create a material with a random name, I do random twice, just to make sure I don't accidentally create the same material twice. And then I will echo the command to create and position a block that is 0.5 in scale. And then I am going to create a new material with the name we generated up here. And oh, I said three lines. It's actually five lines of code for each pixel. Then we're gonna set that material to use nodes. Then we're going to set that material's color to the color value that we've created up here. And then we're going to apply that to the active object, which is the cube we just created. All that comes in, it's gonna have this white space at the beginning. So here I'm saying remove all leading white space because Python is white space sensitive, which is one of the main things I don't like about Python, although a lot of people will praise it for that. And yeah, and that will give us our five lines of code for each pixel that then I can copy and paste into Blender. If I look like I'm crying, it's just because I coughed and now my eyes are watering. Anyway, that's it. It's a silly little script. And it might seem very inefficient and you saw it takes a while to paste in and could definitely be improved. It was just something I did while I was bored. This is a lot more efficient than the way I did it years ago where I manually placed blocks and colored them over an image. And yeah, they're each individual block so then you can add physics to it and make them fall and crash or whatever you wanna do just for fun, just to work on my skills both in Blender and in Bash. So thank you for watching. Visit filmsbychrist.com. That's Chris of the K. As always, there's a link in the description. There'll be a link in the description to this code. If you wanna improve upon it, I would love to see your changes. If you do come up with a script in Blender, which is very, very possible to take the image and have Blender just create the image in cubes without the need for the Bash script would be a much more efficient way to do it. But again, sometimes you can look at the right way to do it and then sometimes you can just do it in with the skills you know or you know. So that's it. Filmsbychrist.com. That's Chris of the K. There's a link in the description as always. I hope that you have a great day. Be sure to support me, Patreon, Libre Pay. You can buy me a coffee, I guess, even though I don't drink coffee. Thanks for watching and again, have a great day.