




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Python Image Library PIL 10/13/05 PIL What is it? Pythonic library for lLoading and Saving images (diverse formats) lScaling, cropping, compositing, transforms, bands (e.g. alpha channel) lDrawing text and basic shapes Akin to the program GIMP (*GIMP also has a nice python API called GIMP-Python) PIL - Examples Image resizing or format conversions Adding save/load support into your application * Font support also handy Chart generation (also see PIDDLE ) Thumbnail generation Watermarking or adding legend PIL API - Concepts Image from file or newly created import Image im = Image.open(“vacation.jpeg“) newIm = Image.new (“RGBA”, (640, 480), (255, 0, 0) Format file format print im.mode, im.size, im.format RGB (1024, 768) JPEG im.save (“vacation.png”) OR im.save (“vacation.png”, “PNG”) PIL API - Concepts Resampling Filters lNEAREST, BILINEAR, BICUBIC, ANTIALIAS smallIm = im.resize ( (128, 128), Image.ANTIALIAS) Sizes tuple of width and height Bounding boxes tuples of x1, y1, x2, y2 l0,0 is always upper left PIL API - Concepts Mode gray scale “L”, color “RGBA” “RGB”, etc. l1 (1-bit pixels, black and white, stored with one pixel per byte) lL (8-bit pixels, black and white) lP (8-bit pixels, mapped to any other mode using a colour palette) lRGB (3x8-bit pixels, true colour) lRGBA (4x8-bit pixels, true colour with transparency mask) lCMYK (4x8-bit pixels, colour separation) lYCbCr (3x8-bit pixels, colour video format) lI (32-bit integer pixels) lF (32-bit floating point pixels) Color specified as 32bit value, tuple, or string lmyColor = (255, 0, 0, 128) # full red, with 50% alpha lmyColor = 0x7f0000ff# full red, with 50% alpha lmyColor = “#00ff00” # web color lmyColor = “rgb (75%, 0%, 0%)” lmyColor = “hsl (0, 100%, 50%)” PIL API - Concepts Bands the separate color channels bands = im.split () rIm = bands 0 aIm = bands 3 remadeImage = Image.merge (“RGBA”, (rIm, gIm, bIm, aIm) grayscaleIm = Image.open (“myAlpha.gif”) remadeImage = myImage.putalpha (grayscaleIm) # replace the alpha band PIL Slicing & Dicing Thumbnails lModifies in-place lPreserves aspect ratio myImage.thumbnail (128, 128), Image.ANTIALIAS) Crop bounds = (100, 100, 400, 400) cutoutIm = myImage.crop (bounds) Paste PIL Slicing & Dicing Blend/composite Rotate Transpose lROTATE_90/180/270, FLIP_TOP_BOTTOM, FLIP_LEFT_RIGHT l fixedIm = myImage.transpose (ROTATE_90) PIL - Drawing ImageDraw module creates drawing surface for image import Image, ImageDraw im = Image.open(“vacation.jpeg“) drawSurface = ImageDraw.Draw (im) import Image, ImageDraw im = Image.open(“vacation.jpeg“) im.getpixel ( (4,4) ) im.putpixel ( (4,4), (255,0,0) PIL - Drawing Basic methods of drawing surface lchord arc pieslice (bounds, strtAng, endAng) lellipse (bounds) lline (coordSeq) lpoint (coordSeq) lpolygon (coordSeq) lrectangle (bounds) # first coord inclusive, second coord exclusvie Common optional args for these methods lfill=fillColor loutline=outlineColor PIL Drawing Text Text drawSurface = ImageDraw.Draw (im) drawable.text (10, 10), “Hello”, fill=(255,0,0), font=None) TrueType Font support import ImageFont ttFont = ImageFont.truetype (“arial.ttf”, 16) drawable.text (10, 10), “Hello”, fill=(255,0,0), font=ttFont) References Python Image Library l/products/pil/ Other documentation sources lPIL Handbook l/imagingbook/ lNice pdf from New Mexico Tech l/tcc/help/pubs/pil/ BMP BUFR (identify only) EPS (write-only) FITS (identify only) GIF GRIB (identify only) HDF5 (identify only) IM JPEG MPEG (identify only) MSP PALM (write only) PCX PDF (write only) PNG PPM TIFF WMF (identify only) XBM XV Thumbnails CUR (read only) DCX (read only) FLI, FLC (read only) FPX (read only) GBR (read only) GD (read only) ICO
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 河北省邢台市第三中学2026届化学高三第一学期期中考试模拟试题含解析
- 广西桂林市2024-2025学年高二下学期期期末考试英语
- 8上Unit2HomeSweetHome单元词汇短语深度默写1默写版
- 化妆师入行基本知识培训课件
- 县妇联面试题目及答案
- 启东中学七下数学试卷
- 太仓幼师面试题目及答案
- 机械传动基础知识培训课件
- 事业人才面试题目及答案
- 社区中学面试题目及答案
- 竣工资料移交清单
- 农业绿色发展背景下我国化肥减量增效研究
- 硬质合金成型工(三级高级工)理论考试题库(汇总版)
- 高一1学生情况调查表
- 涂料用常用树脂课件
- 医院类建筑室内装饰装修施工关键技术
- 营销经理助理历年真题和模拟试题
- 滇中引水工程
- 准东-华东±1100kv特高压直流输电线路工程杆塔设计原则
- 铁路货车制动故障分析与处理
- krones旋盖系统控制原理及参数设定
评论
0/150
提交评论