 How's it going everybody welcome back to another Python programming Python challenge video I'm your host root of the null and today we're moving on to challenge number seven in the last tutorial We just got through challenge number six We got thrown into our new challenge with the oxygen URL and here we are we're staring at this This page with just an image and nothing else here let's do some investigation like we always do let's view the page source and Again, there's pretty much nothing here. We got Got our image file oxygen dot PNG and that's about it Don't really know What to do or where to move on from here, but I mean I guess I guess let's try it I'm thinking if all we've got handed to us is an image We're probably Well, I mean since we're working with Python, right? We're probably gonna end up using the Python image library If you're on Windows like I am you might need to install that I I already did install it on my on my on the one that I'm working on right now so I've got my text that are open and I'll just do a shebang line and get like a Good thing going. I'll just save this at my desktop What is it seven seven dot pi and C drive Okay, and Let's get this image actually because if we're gonna try manipulate it we should download it I'm gonna right-click it and click save image as I'm just gonna bring it to my desktop Okay, so it's right in the same location and place as my script over here Um You guys know we could have just downloaded it with URL lib in Python That's kind of a cool Pythonic way to do it But I mean I'm sure you guys know how to do that if not you can look at my URL lib tutorials and anyway we're just gonna move on I'm gonna go and import the image library and What we'll do is we'll say oxygen I Guess we can create a variable to actually hold the image when we open it up image Dot open and we the file name that it saved us was oxygen dot PNG so now if I I print out oxygen We get here, okay. Yep, we do got this image here. Oh, hey Png image Png image mode equals RGB a size. Okay, cool. So it tells us the size here Let's actually save that because we might need to go through it with Actually size equals width and height Equal 629 and 95 Random and character here. Okay, so we got our oxygen thing and Here we go. There's our image You know, I'm gonna open it up in paint here I got I've got the image here open with Paint because I want to be able to explore a little bit more of it I'll bring this down to you guys can see it zoom in a little bit It looks like I mean, okay, there's the other's pretty obviously like this band of gray blocks here over a bank some river But anyway, the the the gray blocks are probably we're gonna be focusing on okay, so they're all they're all black, right? They're all variations of gray or black and they don't get they don't get that close to white So I'm thinking because you know if you have the the RGB values If you've got RGB values, they're in this triplet sort of thing with like their representation for red the representation for green and then Their representation for for representation for blue, right? So if you've got them all black like black is simply the absence of colors 0000 and white is the Entity of color 255 255 255 so if you're getting a variation of black or a shade of gray or a shade of white It's the values RG and B are all gonna be the same number, but it's in between 255 and 0 0 and 255 anyway, so but anyway, like I said, they're all gonna be the same number the same number number number number so I kind of wonder if Like that that number is Gonna represent some Text like if we if we pass it to the character function and Python. I wonder if it'll Like ASCII will give us a value. Let's play with it So if we wanted to get to that let's look at our paint We know in in image in the image library that we've gotten Python there is a get pixel Function and I mean I've shown you this I think in my other Image library module tutorial series so we can use we can pass in a tuple or a tuple here with x and y coordinates to Actually get the color values at a certain pixel so if we're trying to go through it here what we're gonna do is we're gonna We need the coordinates of each of these blocks so let's say the Y coordinates Okay, anywhere inside the block So I'm looking down here right right here where my mouse cursor as you can see paint is Showing us the coordinates of the of the mouse Right now it looks like okay 47 or 48 48 gets us in the pixel gets us in the block so okay, let's say Y can equal 48 That's fine and our x value. That's what's gonna change you see all these different blocks here We're gonna want to get somewhere inside one of them so zero okay? That will work just fine. We'll start at zero and then we'll move to get to the next block So I think this one has the size of what? Okay five to get to anyone so 10 should be the next one. Well now I'm at 10, but I'm At 10, but I'm still in this block so that doesn't work for us Looks like the next block starts at 12 if you guys can see these colors. I know I know it's all gray Just slightly darker versions of gray, but next one starts at 19 so What if we went for increments of six six it's gonna 12 that works for us when I get to 18 I'm still in this block. So that doesn't work. Let's try seven So start at zero go to seven. I'm in the other block add seven go to 14 I'm in the other block at seven go to 21 in the other block at seven go to 28 in the other block. Okay 35 that works for us Yeah increments of seven work for us. Let's try it So if we're gonna loop through every single one of these We need a for loop and we're counting for x values. Let's say for x in range of Zero started zero and we're gonna go all the way to the very end of the picture. Oh actually Looks like the block stop here, right? Let's go to 607. Yeah, 607 is the very last. Let's say 607 and step can equal seven is what we said earlier. So yeah step and So now what we'll do is We can just print out the character form of Oxygen dot get pixel Because that's the handle that's holding our file, you know, so oxygen dot get pixel at x and y X is gonna change while we have set to 48 So let's try this control B No, and integers required What does that mean? Oh, yeah. Yeah. Yeah. So what this is doing? Check it out If we run this we get all of these different values for uh, you know and like I said the Rg and b values red green and blue values are all gonna be the same because we're looking at Variations of gray or variations of black and white so we can choose any of these red green or blue We just index it with With zero or one or two and let's just use zero and that will get us Okay, one of the values So now we'll change this to a character And I'm just gonna add a comma here so it doesn't print new lines every time and let's run it. Oh Check this out smart guy. You made it The next level is 105 Okay, now we have to go through the same thing or converting these values to uh, You know text With our chr function in Python. So what I'm gonna do is actually set up a new string So it's equal nothing I'm just gonna say new string plus Equals this and then at the end of it print out new string. So now Remove the comma at the end there. So we don't it doesn't think it's a tuple. So now, okay So now there's no spaces smart guy. You made it the next level is this I'm gonna copy this output And I'm gonna create a to change equals This Okay, so now for item in to change Um Let's I'm coming out our loop here And I'm gonna say new string plus equals Character item So now whoo-hoo. All right integrity So what this did is it went through each and every item inside this to change array that we got from our original loop It was reading these pixels from the image file That we were given at the at the at the prompt at the page here, you know, so And then it changes them all to characters. That's awesome Now uh Looks like our next one is integrity. Let's go. Let's do it So in our URL bar change oxygen to integrity Hey enter Yeah, all right, awesome channel number eight guys sweet we did it Thank you guys for watching. I mean, I hope you like this one I hope it was kind of cool and fun to follow through with I really liked that we were able to use the oxygen Sorry, not the oxygen. I'm just reading the title here I really like that we were able to use the image library to like look through this file That's kind of cool. So all right. Thanks guys. Hope you enjoyed this tutorial and I'll see you in the next one