Search Header Logo
Pillow

Pillow

Assessment

Presentation

•

•

Practice Problem

•

Hard

Created by

Аңсар Әкім

Used 2+ times

FREE Resource

13 Slides • 5 Questions

1

Creating images in Python

​Visual programming is essential in today's digital landscape, enabling effective communication and creativity.
It plays a pivotal role in web development, data science, and user experience design.

2

  • Determine Colors by RGB Code

    • Understand RGB color representation.

    • Understand how to specify colors using RGB codes.

  • Use PIL for Image Manipulation

    • Learn Image module commands in Pillow (PIL).

    • Explore loading, creating, resizing, and saving images.

  • Apply Graphic Primitives

    • Discover how to use graphic primitives for drawing.

    • Create visual elements, such as lines, circles, and rectangles, in Python.

​Learning Objectives

3

  • Web Development: Creating visually appealing websites and user interfaces.

  • Data Science: Visualizing data and results for better understanding.

  • Game Design: Developing graphics, animations, and interactive elements.

  • Digital Art: Crafting digital illustrations, designs, and multimedia.

Visual programming is a versatile skill used in a wide range of fields, including:

4

  • RGB (Red, Green, Blue) is a fundamental color model used in digital imaging.

  • RGB codes represent colors by specifying intensity levels of each component (0 to 255):

    • (0, 0, 0) represents black.

    • (255, 255, 255) represents white.

    • Equal component values yield various shades of gray.

    • (255, 100, 100, 128) - ???

RGB Color Scheme

RGB in Python

  • ​In Python, RGB colors are represented as tuples, like (255, 0, 0) for red.

  • Python provides a straightforward way to work with RGB color codes.

6

  • Pillow (PIL) is a Python Imaging Library that simplifies image processing.

  • It offers a powerful set of tools for image manipulation and creation.

Introduction to PIL Library

Mini-research 1. Image Manipulation with PIL

  • Explore commands in the Image module of Pillow:

  • Installation

    • Load: Open and load images.

    • Create: Create new blank images.

    • Resize: Adjust image dimensions.

    • Save: Save modified images to files.

7

Multiple Choice

Which code snippet correctly opens an image file named "example.jpg" using the Pillow library?

1

from PIL import Image img = Image.open("example.jpg")

2

import Image img = Image.open("example.jpg")

3

from Pillow import Image img = Image.open("example.jpg")

4

import PIL img = PIL.open("example.jpg")

8

Multiple Choice

Which code snippet correctly resizes an image named "input.jpg" to 300x300 pixels using Pillow?

1

from PIL import Image img = Image.open("input.jpg") img = img.resize((300, 300))

2

from PIL import Image img = Image.open("input.jpg") img.resize((300, 300)).show()

3

from PIL import Image img = Image.open("input.jpg") img.thumbnail((300, 300))

4

from PIL import Image img = Image.open("input.jpg") img.resize(300, 300).show()

9

Multiple Choice

Which code correctly saves the image in "output.png" format using the Pillow library?

1

from PIL import Image img = Image.open("input.jpg") img.save("output.png")

2

from PIL import Image img = Image.open("input.jpg") img.save("output.jpg")

3

from PIL import Image img = Image.open("input.jpg") img.save("output.png", format="JPEG")

4

from PIL import Image img = Image.open("input.jpg") img.save("output.png", format="PNG")

10

Introduce graphic primitives, essential for creating drawings:

  • Lines: For straight-line segments.

  • Circles: To draw circles and ellipses.

  • Rectangles: To create rectangular shapes.

  • Complex Graphic Composition

Mini-research 2. Graphic Primitives

Drawing with PIL

  • Provide code examples for drawing shapes and lines using PIL:

    • Demonstrate how to create visuals within Python scripts.

    • Showcase examples of drawings.

11

Multiple Choice

What will be the result of the following code?

from PIL import Image img = Image.new("RGB", (200, 100), (255, 0, 0)) img.show()

1

It creates a white image

2

It creates a black image.

3

It creates a red rectangle.

4

It raises an error.

12

Multiple Choice

Which code snippet creates a new image with a blue background and size 400x300 pixels using Pillow?

1

from PIL import Image img = Image.new("RGB", (400, 300), (0, 0, 255))

2

from PIL import Image img = Image.new("RGBA", (400, 300), (0, 0, 255, 255))

3

from PIL import Image img = Image.new("RGB", (400, 300), (255, 0, 0))

4

from PIL import Image img = Image.new("RGB", (300, 400), (0, 0, 255))

13

media

Task 1

Check if Pillow library is

installed on your

computer.

If yes, uninstall using

pip uninstall pillow

command in command

line

Install using pip install

pillow command in

command line

14

media

Task 2

• Choose any image.

• Determine the size of image using

Pillow

• Determine the color of the left-top

pixel using Pillow

• Check the output with Photoshop (if

you have)

15

media

Task 3

Create this rectangle using Pillow

with given parameters. Size 200 x

200, color blue (try other colors

using RGB). And save it on

desktop.

16

media

Task 4

Draw a line using Pillow

17

media

Capabilities of Pillow library

https://www.youtube.com/watch?v=5QR-

dG68eNE&ab_channel=ClearCode

Watch a video to see other capabilities of library in

practice.

18

media
media

Task 5

Create a beautiful image using

the Pillow and your creativity.

pattern-tertiary

Creating images in Python

​Visual programming is essential in today's digital landscape, enabling effective communication and creativity.
It plays a pivotal role in web development, data science, and user experience design.

Show answer

Auto Play

Slide 1 / 18

SLIDE