From 2d4d8aad73df7282ecba5788c097ff06cd18f867 Mon Sep 17 00:00:00 2001 From: Hui Lan Date: Mon, 3 Jun 2019 20:31:56 +0800 Subject: =?UTF-8?q?LectureNotesOnPython.rst:=20added=20two=20sections:=20?= =?UTF-8?q?=E5=88=A9=E7=94=A8=E7=AC=AC=E4=B8=89=E6=96=B9=E5=BA=93=E5=87=BD?= =?UTF-8?q?=E6=95=B0=20pillow=20&=20=E5=93=88=E5=B8=8C=E8=A1=A8=20(hash=20?= =?UTF-8?q?table)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LectureNotesOnPython.rst | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/LectureNotesOnPython.rst b/LectureNotesOnPython.rst index cd99d08..02d2875 100644 --- a/LectureNotesOnPython.rst +++ b/LectureNotesOnPython.rst @@ -2459,6 +2459,43 @@ defaultdict printall(1,2,3, a=1,b=2,c=3) +利用第三方库函数 pillow +--------------------------------------------------- + +我们希望建立一个私人相册, 需要通过编程实现缩略图(thumbnail)。 为此,利用第三方提供的库 pillow 。 + + +.. code:: python + + + from PIL import Image + import os + # details: https://pillow.readthedocs.io/en/stable/reference/Image.html#examples + def make_thumbnail(picture_fname, size): + image = Image.open(picture_fname) + image.thumbnail((size,size), Image.ANTIALIAS) + fname, fext = os.path.splitext(picture_fname) + image.save(fname + '_small.jpg') + image.close() + + + make_thumbnail('ottawa.jpg', 200) + + +以上代码定义了一个函数 make_thumbnail, 可以帮任何图片生成缩略图。 + + + + + +哈希表 (hash table) +--------------------------------------------------------- + +参见书本 Think Python 2e 第 B.4 节以及相应的代码 http://thinkpython2.com/code/Map.py 。 + + + + 参考 -- cgit v1.2.1