diff options
Diffstat (limited to 'LectureNotesOnPython.rst')
-rw-r--r-- | LectureNotesOnPython.rst | 37 |
1 files changed, 37 insertions, 0 deletions
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 。 + + + + 参考 |