Let's learn a few more neat things that we can do with images.
Now, here we learned that we're able to save images.
We can convert them.
We can add image filters to them.
And we also learn that we can actually use the save method to give a new name to a file and then also
give it an extension with the second parameter so we can convert from, let's say, a JPEG to a PNG
file like this.
Another neat thing that we can do is also actually do something called show.
And this is just going to show us the image.
Let me show you.
Ha ha.
Get that pun.
Let me show you.
All right.
There you go.
We see that it's now opening up the file and showing me the grayed out black and white, 1920s Pikachu.
Awesome.
We can also rotate our images so I can say filtered image.
And this image I want to rotate.
Let's say 90 degrees.
And I'm actually going to move this above the safe so that we can see the effects.
If I run this.
And go to Gray Dot, P&G.
And let's just assign this to a crooked variable.
And this crooked variable which stores the new image is where we're going to save.
So let's just oops, let's save that and run this.
And if we now go to Gray Dot, P&G, look at that.
We've got a crooked Pikachu and we can again do different things.
Let's do 180.
So we have upside down Pikachu.
And there we go.
We have upside down Pikachu, so that's great.
We can rotate images.
We can also resize the images.
So let's just say resize here and this is going to be called resize.
And instead of rotate, what we'll say is we'll say.
Resize.
And we can say that this image remember it was 640 by 640, I'm going to resize it to 300 by 300.
So a nice little thumbnail if I run this.
Oh, and you see that I get an error here.
And what I actually should have done here is the resize accepts a tuple.
So I have to add brackets around here.
So if I run this again, let me clear and run this again.
And we go to Great Pag.
Look at that.
Pikachu is a lot smaller than he used to be.
Pikachu is tiny now.
So we got tiny grayed out Pikachu.
So that's great.
I can resize images, which is really, really useful.
Now, let's say I wanted to crop my Pikachu image.
What can we do?
Well, instead of me telling you, let's just find out.
We can go to the documentation website and simply search for crop.
And if we keep scrolling down, keep scrolling down, well, let's just do a dot crop to see if there's
an actual function that we have.
And let's go over here and we see that we have a crop over here.
So cutting, pasting and merging images.
So let me just zoom then so you can see it a little bit.
We see exactly how it can work.
We can just pick the.
Pixel location of the four corners and crop an image.
So let's just copy that.
And try it out.
So we have the region.
So let's just say region.
Or Let's just remove this and crop the filtered image.
With the box like this.
And if we save this region image and run our code.
Let's go to Pikachu and look at that.
Just the face of Pikachu.
He's so cute.
All right, let's pretend that I didn't make that choice.
Let's keep going.
So there we have it.
We can even crop images.
I mean, this is pretty basic stuff, but you see the power of image processing, whatever you want
to do, you're not going to know at the top of your head.
Instead, you're going to go to the documentation and say, Hey, I want to have a blurry, grayed out
image.
How can I do that?
Well, you just search the documentation page and learn the commands, and you write your file and that's
the key, right?
You're not going to know the top of your head, the entire library, when the need arises.
You just read the documentation.
That's what good developers do.
All right.
We've learned a lot, but we still have a few more things to learn.
So let's take a break and I'll see you in the next one.
Bye bye.