Welcome back.
It's time to apply what we just learned and do an exercise and build our own project.
Now, what is this project?
This project is going to be a JPEG two PNG converter.
You remember our pokédex, right?
Our Pokédex.
Are all these cute little pokemon, but they're all in JPEG format.
Now JPEG image file format.
You can read up on it, but I prefer PNG.
There are some benefits that PNG files have, especially for these type of images.
So for example, if you're a web developer, these types of images with not a lot of color or just a
few colors, you can see over here, blue, brown, white.
They're actually better when you develop websites to use PNG.
Again, that's beyond the scope of the course.
You can read up on this on your own, but a JPEG to PNG converter is really, really useful.
So how can we build it based on what we've learned?
I'm going to get you started.
And the rest, I'm going to try and see if you can figure out on your own.
So what I'm going to do first is create a new file in here.
And I'm going to use the command line.
I can use touch here because I'm using a mac.
If you're using windows, this command is different.
And that's something that we've already talked about before.
You can also just manually on your computer, just say new file so you can just right click and say
new file, whatever you want.
Well, I already did this.
So instead of doing touch, I'll just create a new file.
And what we'll call it is I'm going to call it JPEG to PNG converter.
Dot pie.
There we go.
Now, what do we want this to do?
Well, we want a Python script that I can run that works like this.
I want to be able to say Python three and then say JPEG to pag converted or pi and then give it to arguments.
The first argument is I wanted to give the folder name, so I'm going to say Pokédex and we're going
to add a slash here to show that this is a folder.
So I want you to open the Pokédex folder.
And then the second parameter is the new folder that I want to create.
So let's just call it new.
So this new folder doesn't exist, but I want to be able to create it.
And by the way, if you're on a windows, this slash will be the other one.
It'll be the back slash like this.
But essentially what I want to do is run this command.
It's going to look through all the images here and convert them into a jpeg and put them in a new folder
called New.
So let's build that script, and I'm going to get you started with a little hint.
What we need to do is we need to be able to grab these arguments.
And also grab all these files.
And from the previous sections, we should know how to do that.
What I'm going to do is import the CIS module and import the OS module.
And of course, from the pillow library, I'm going to import PIL from.
Image.
It's import here.
There you go.
Now the first step is to actually using the CIS module.
Grab the first.
And second argument.
So remember, that's the Pokédex and the new folder.
So that's the first thing we want to do.
The second thing is to do well based on whether this exists or not, to check if new exists.
Or this folder exists and if not, create it.
Right.
So if this doesn't exist, we have to create the folder so we can put the images in.
And then finally, what we want to do here.
And this is the tough part.
We want to loop through this entire folder, so loop through pokédex.
And then we want to convert images to P&G.
And then finally we want to save them to the new folder.
This is a tough one.
It combines a lot of the things that we've learned up until now.
You might not get it right away because it is a little tricky.
So don't worry.
In the next video, I'm going to show you how to solve this problem.
But what you might want to learn is how to Google first of all, how to use CEST to grab the first and
second argument.
How to use the OS module to grab the path.
So that you can say, Hey, I want these files in Pokédex and I want to write to this new file.
So we're going to use the OS module for that.
And then obviously we're going to use the pillow module to convert the images to PNG, something that
we've seen before.
This exercise is going to require a bit of Googling on your case, which is a good skill to develop.
So in the next video, I'm going to show you how to do this.
I'll see you in that one.
Good luck.
Bye bye.