Open an image

Workshop Resources

To change an image, we must open an image. We can use the Pillow Image module we just imported in the setup. Let’s first find some images to open. Find an image of your choice and download it. You can also use the one we use in this workshop: Click to download.

For example, to upload the cat.jpg file:

You should see the JPG file on the left side once you’ve uploaded it. Note, your image may have a different extension.

Next step is to open that image within code. There are functions within the Pillow Image module we imported that allow us to do this.

image = Image.open("cat.jpg")

If you are using a different image, then make sure you put the name of the file within the quotes. The code above opens the JPG image and stores that image in the variable image. To check that the image variable has the image, we can then save it as a new image. This way the image will show in the window.