 Hello, today we're going to be taking images and converting them to text. Now I'm not talking about ASCII art, we're not taking images and making them into little characters that you can view in a terminal, we've done that before, that's been done. What we're going to do is actually use image magic, which if you've never used before, image magic is a great command line tool that basically it's like Photoshop or GIMP but for the shell. If you want to manipulate images in any way or convert them from one format to another, image magic can do it. If you installed image magic, it actually installs a variety of commands, one of which is the convert command. So if you want to convert PNGs to JPEGs or JPEGs to PNGs or GIFs or GIFs or whatever, you can do that with simple command. You just say convert, you give it an input file name, you give it the output file name, image magic is smart enough to go, ah, I know that extension and we'll convert it to it. But we can convert it to a text file as well, a text file that is actually just a list of coordinates for each pixel as well as color values in different formats. Now you might ask, why, Chris, why would I want to take my images and convert them to text? Well, I don't know what you do on your spare time, but I will give an example here and then in a future video, I'm going to do a fun little script just for fun, but theoretically you could do a lot with this. Again, it's going to convert it to a text file as you see with coordinates for each pixel in the image and the color values and image magic can take these text files and recreate PNGs, JPEGs, whatever from these text files. So theoretically, you could generate images through text with scripts. You could take images that you've converted to this text, you can change the color values and move them around and then convert them back to images. It's probably not the most efficient way to do it. Image magic already has most functionality you need if you want to convert or modify the color of pixels or the values of the pixels or the position of the pixels or the resize stuff, but it could be fun. And as an example of something I did in the past, and again, it's not the best way to do it, but probably over 10 years ago when I first started messing with shell scripts, I was like, I wonder if I could create a motion tracker with a bash script. So what I ended up doing was I took a video file, I converted it to a series of images. I might have used FFMPEG for that, but image magic might have functionality to do that as well. Anyway, once they were images, what I did was I had the image magic convert, convert each one of those images to text. So it's not real time tracking. And what I did in the video was I held a red LED. So it was a very bright LED. And I actually had image magic, just a threshold so that the red was very, very bright. And then once I converted it to a text file, I ran some sort of said command or something on it that went and looked for the very first pixel it could find that was a true pure red color. It would get the coordinates of that. Then it would take another image. And my example, I had a little image of tux, and it overlaid that image at those coordinates off setting it a little bit. And then it did that for every image. And then I recompiled that into a video. Again, not a very efficient way to do it, but just showing that I could actually create a motion tracker in a way, it's really tracking a color, and create a video out of that with overlays. Very, very slow, very, very efficient, but it gets those creative juices going, you know, it's like you do stuff like that. And it just helps you become a better programmer. So that's one example and a few theoretical examples. And again, I have a video coming up in a couple of days where I'm going to do something fun with this in Blender. Again, a very efficient way, but it's a fun little project I came up with. But let's go ahead and see how this works. It is so simple. Okay, here we go. On the left, we are on the shell. On the right, we are in our file manager. We're in the same folder for both. If I list out, you can see the same files over here that are over here. Most of them are small little PNGs. And one of them is a larger JPEG. That is a image of me and my son in Gatlinberg with some snowmen. So I'm going to show you real simple. If you have image magic installed, should be in your repositories. It's such a common tool. If you upload files to a website, there's a good chance it's using image magic to manipulate those images for you, resize them and whatnot. It is everywhere. It is a great tool. And what I type in VIM, we're going to say convert, convert. And I'm going to give it this Mario PNG. And I'll have to just say is Mario.txt. And again, image magic goes, oh, I know this extension. You want it to be a text file. So now I can cat out Mario.txt. And look, it is our image each pixel, its coordinates, and its color value in a few different formats here. And we can also do it with the larger image of me. So I can say convert and I can use this larger JPEG. It's, oh, I should tell it where I want it to go. I'll just say me.txt. It's going to take a moment because again, this is a full size image and it's writing a line for every pixel. So once it's done doing that, we'll be able to open that up and give it a moment, give it a moment, give it a moment, give it another moment, give it another one. There we go, VIM, me. Again, not the most efficient way to do things. But again, I can go to the top here and you can see it tells that this is image pixel. It gives you some information about its values and we can go through here. And again, we can see every single pixel's value individually on its own line. So let's go ahead and exit out of that. Now, that's great. What if we want to convert it back? So let's go ahead and we'll say convert, or I already did the Mario one. Let's go convert mario.txt to mario.txt. This time I'll do JPEG. Now, the original one, the PNG, has a transparent background. It's going to automatically replace that with a black background, although you can tell image magic to use different fill colors for the background. But there we go, we went from a PNG to a text file to a JPEG file. And of course, if I was to convert mario.txt to m.png, it would actually create a PNG still with the transparent background here. Again, these are very small. It's a 16 pixel image, 16 pixels high. I don't remember what the width is a little bit less. So it doesn't take very long. Now, that's great in all we've created files. We converted from an image to a text and from the text back into an image. But let's say you want to manipulate this. With said, you do want to run some processing on it. You don't necessarily want to dump it to a file. Image magic's got you covered. Let's go ahead and do a different one. We'll just pick a different image. We'll do one of the turtle images, turtle1.png. Instead of saying, you know, turtle.txt, what we'll say is text. We're saying we want this to be a text file. colon dash. This says pipe at a standard output. So instead of going to a file, it's going to put it right on our screen here and we can process through that. We can do the same thing with the larger image of me. So IMG, JPEG, boom. And again, it's piping all through there, but we could use said to manipulate this in whatever we want. I'm just using said as example, whatever tools you want from the shell. That is it. And again, this is super simple to do. Again, this is not something you probably do day to day for most of us, but it's interesting to know because maybe someday you will have a scenario where you want to do something like this. And again, I have a little fun project coming up in the next video where I'm going to use this in a weird way because I'm going to use it to generate some Python script for Blender. So stay tuned for that. Let's go ahead and tell you to have a great day. Visit filmsbychris.com. That's Chris the K. There's a link in the description. I will also link to my Patreon page, my PayPal page, my Libre pay page and recently I had the whole buying me a coffee thing. So far, most of us haven't been used. If you like my videos and you want to keep seeing them, think about supporting in those ways. Thank you for watching. And as always, I hope that you have a great day.