已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年黑龙江农业经济职业学院单招职业适应性考试题库附答案
- 2026年荆州职业技术学院单招职业倾向性考试模拟测试卷附答案
- 2026年山西体育职业学院单招(计算机)测试备考题库及答案1套
- 2026年辽宁现代服务职业技术学院辅导员招聘备考题库附答案
- 2026年西安职业技术学院单招(计算机)考试备考题库附答案
- 2026年崇左幼儿师范高等专科学校单招(计算机)测试模拟题库附答案
- 2026年新疆职业大学单招职业适应性测试模拟测试卷附答案
- 2025年阿克苏职业技术学院单招(计算机)测试模拟题库附答案
- 2026年苏州信息职业技术学院单招职业适应性测试模拟测试卷附答案
- 2026年安徽国防科技职业学院单招(计算机)测试模拟题库附答案
- 非新生儿破伤风诊疗规范(2024年版)解读
- 《电动汽车CAN总线测试规范》
- FOCUS-PDCA改善案例-提高术前手术部位皮肤准备合格率医院品质管理成果汇报
- 【MOOC】数据库原理与应用-北京林业大学 中国大学慕课MOOC答案
- 知识创业思维与方法(湖南师范大学)知到智慧树章节答案
- 2024屋顶分布式光伏场站设备运维规程
- (高清版)JT∕T 1402-2022 交通运输行政执法基础装备配备及技术要求
- 高中英语英汉互译集中训练题350题(含答案)
- 哪些荣誉奖项不可以作为评审因素
- 土地综合整治 投标方案(技术方案)
- 钣金必备基础知识钣金工培训
评论
0/150
提交评论