python图像处理库Pillow基本使用方法
安装pillow
pillow的文档页面,documentation of Pillow
生成一个有单一颜色的图像
from PIL import Image, ImageDraw img = Image.new(mode, size, color) img.save(filename)
There are various values for mode listed in the documentation of Pillow. For example RGB and RGBA can be modes. The size is a tuple in the form of (width, height) in pixels. The color can be a word such as 'red', or a triplet for RGB colors of 3 values between 0-255.
例子
from PIL import Image img = Image.new('RGB', (60, 30), color = 'red') img.save('pil_red.png')
使用RGB三个数值创建颜色
from PIL import Image img = Image.new('RGB', (60, 30), color = (73, 109, 137)) img.save('pil_color.png')
在图像上写字
from PIL import Image, ImageDraw img = Image.new('RGB', (100, 30), color = (73, 109, 137)) d = ImageDraw.Draw(img) d.text((10,10), "Hello World", fill=(255,255,0)) img.save('pil_text.png')
换不同的字体
There are a number of ways to select the font used for writing on the image. We need to import and use the ImageFont to load a TrueType font. Mac OSX supplies a bunch of fonts that are located in the /Library/Fonts/. On other platforms you'll need to locate the files yourself and then pass the full path to the function. Alternatively you could include the font-file in your application and then you can know where is the font-file relative to your code.
In this example we load the font using the truetype method of the ImageFont passing to it the path to the fonts and the size of the fonts to be loaded.
from PIL import Image, ImageDraw, ImageFont img = Image.new('RGB', (100, 30), color = (73, 109, 137)) fnt = ImageFont.truetype('/Library/Fonts/Arial.ttf', 15) d = ImageDraw.Draw(img) d.text((10,10), "Hello world", font=fnt, fill=(255, 255, 0)) img.save('pil_text_font.png')
转载于:https://www.cnblogs.com/roadwide/p/10353038.html
- 点赞
- 收藏
- 分享
- 文章举报
- 使用python进行图像处理的基本方法
- 详解Python图像处理库Pillow常用使用方法
- python使用TensorFlow进行图像处理的方法
- Python学习之使用Pillow(PIL)进行图像操作方法详解
- Python环境Pillow( PIL )图像处理工具使用解析
- Python 之 使用 PIL 库做图像处理(pillow+ImageDraw)
- python使用opencv对图像mask处理的方法
- js一个典型的对象写法,推荐使用这种格式,用于处理图像的基本方法、
- 怎样使用Python图像处理?
- python使用socket远程连接错误处理方法
- Python 之 使用 PIL 库做图像处理
- python类使用基本方法
- python处理图片之PIL模块简单使用方法
- 在Python中处理字符串之ljust()方法的使用简介
- 使用C#进行图像处理的几种方法
- Javascript图像处理——矩阵基本方法
- Python图像处理库(PIL)的安装与简单使用
- MATLAB基本的使用方法归纳(图像,矩阵及函数)
- 在Python中处理字符串之isdigit()方法的使用
- Python中处理字符串之islower()方法的使用简介