Skip to Content
Python 소개, 제 2판
book

Python 소개, 제 2판

by Bill Lubanovic
May 2025
Intermediate to advanced
630 pages
8h 17m
Korean
O'Reilly Media, Inc.
Content preview from Python 소개, 제 2판

20장. 파이 아트

이 작품은 AI를 사용하여 번역되었습니다. 여러분의 피드백과 의견을 환영합니다: translation-feedback@oreilly.com

예술은 예술이죠? 그래도 물은 물입니다! 동쪽은 동쪽이고 서쪽은 서쪽이고 크랜베리를 사과 소스처럼 끓이면 대황보다 자두 맛이 훨씬 더 나죠.

그루초 마르크스

이 장과 다음 두 장에서는 예술, 비즈니스, 과학 등 인간의 일반적인 노력에 Python을 적용하는 방법에 대해 설명합니다. 이러한 분야에 관심이 있다면 유용한 아이디어를 얻거나 새로운 것을 시도해보고 싶은 충동을 느낄 수 있을 것입니다.

2-D 그래픽

모든 컴퓨터 언어는 컴퓨터 그래픽에 어느 정도 적용되었습니다. 이 장에서 소개하는 많은 무거운 플랫폼은 속도를 위해 C 또는 C++로 작성되었지만 생산성을 위해 Python 라이브러리를 추가했습니다. 먼저 2D 이미징 라이브러리부터 살펴보겠습니다.

표준 라이브러리

표준 라이브러리에는 몇 가지 이미지 관련 모듈만 있습니다:

imghdr

일부 이미지 파일의 파일 유형을 감지합니다.

colorsys

RGB, YIQ, HSV, HLS 등 다양한 시스템 간의 색상을 변환합니다.

O'Reilly 로고를 oreilly.png라는 로컬 파일에 다운로드한 경우 이 파일을 실행할 수 있습니다:

>>> import imghdr
>>> imghdr.what('oreilly.png')
'png'

또 다른 표준 라이브러리는turtle-청소년에게 프로그래밍을 가르칠 때 가끔 사용되는 "터틀 그래픽"입니다. 이 명령으로 데모를 실행할 수 있습니다:

$ python -m turtledemo

그림 20-1은 로제트 예제의 스크린샷을 보여줍니다.

inp2 2001
그림 20-1. 터틀데모 이미지

Python에서 그래픽으로 본격적인 작업을 하려면 서드파티 패키지가 필요합니다. 어떤 것들이 있는지 살펴봅시다.

PIL 및 필로우

표준 라이브러리는 아니지만 수년 동안 Python 이미지 라이브러리(PIL)는 가장 잘 알려진 2D 이미지 처리 라이브러리로, pip 과 같은 설치 프로그램보다 먼저 만들어졌기 때문에Pillow라는"친숙한 포크"가 만들어졌습니다. Pillow의 이미징 코드는 PIL과 하위 호환되며 문서도 훌륭하므로 여기서 사용해보도록 하겠습니다.

설치는 간단합니다. 다음 명령을 입력하기만 하면 됩니다:

$ pip install Pillow

libjpeg, libfreetype, zlib 와 같은 운영 체제 패키지를 이미 설치한 경우 Pillow에서 이를 감지하여 사용합니다. 이에 대한 자세한 내용은설치 페이지를참조하세요.

이미지 파일을 엽니다:

>>> from PIL import Image
>>> img = Image.open('oreilly.png')
>>> img.format
'PNG'
>>> img.size
(154, 141) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python 학습, 제 5판

Python 학습, 제 5판

Mark Lutz
fastai와 파이토치가 만나 꽃피운 딥러닝

fastai와 파이토치가 만나 꽃피운 딥러닝

박찬성, 김지은, 제러미 하워드, 실뱅 거거

Publisher Resources

ISBN: 9798341653764