PIL(Python Imaging Library)是python语言中对图像处理方面的一个开源库,其主要功能模块为Image,对于Image模块,可以使用
from PIL import Image
或者
import Image
由于使用了试用版的chartdir库,在生成图片的时候下面会出现一行提示是非注册版的文字,看起来不太舒服。
如
所以想使用PIL自动地将下面一行去掉,查阅了一下PIL的文档,最后决定使用PIL的crop和paste函数实现功能
实现的代码如下:
import Image
import sys
if len(sys.argv)<2:
print '%s <image file>' % __file__
sys.exit()
else:
filename = sys.argv[1]
img = Image.open(filename)
width = img.size[0]
height = img.size[1]
img1 = img.crop((0,0,width,9))
#img1 = Image.new('RGBA',(width,10))
img.paste(img1,(0,height-9))
img.save(filename)
img = Image.open(filename)
img.show()
这可以使用的方法有两种,第一种是以及被注释掉的方法,即生成一个新的Image,调用Image.new方法。然后将该image粘贴到需要修改的图片上。另外一种为了保持图片的前后背景色一致,从图片的最前头拷贝一部分图片(使用crop函数),然后在粘贴到需要修改的图片上,来完成最下端文字的覆盖。
crop函数带的参数为(起始点的横坐标,起始点的纵坐标,宽度,高度)
paste函数的参数为(需要修改的图片,粘贴的起始点的横坐标,粘贴的起始点的纵坐标)
下面是处理结果之后的图片:
PS.使用chartdir生成图片的Python脚本
#!-*- encoding: utf-8 -*-
#!/usr/bin/python
from pychartdir import *
# The data for the bar chart
data = [450, 560, 630, 800, 1100, 1350, 1600, 1950, 2300, 2700, 3200, 3800]
# The labels for the bar chart
labels = ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月",
"十月", "十一月", "十二月"]
# Create a XYChart object of size 600 x 360 pixels
c = XYChart(600, 360)
# Add a title to the chart using 18pts Times Bold Italic font
c.addTitle("卖家月份销售图表", "simsun.ttc", 18)
# Set the plotarea at (60, 40) and of size 500 x 280 pixels. Use a vertical gradient
# color from light blue (eeeeff) to deep blue (0000cc) as background. Set border and
# grid lines to white (ffffff).
c.setPlotArea(60, 40, 500, 280, c.linearGradientColor(60, 40, 60, 280, 0xeeeeff,
0x0000cc), -1, 0xffffff, 0xffffff)
# Add a multi-color bar chart layer using the supplied data. Use soft lighting effect
# with light direction from left.
c.addBarLayer3(data).setBorderColor(Transparent, softLighting(Left))
# Set x axis labels using the given labels
c.xAxis().setLabels(labels)
# Draw the ticks between label positions (instead of at label positions)
c.xAxis().setTickOffset(0.5)
# Add a title to the y axis with 10pts Arial Bold font
c.yAxis().setTitle("人民币 (元)", "simsun.ttc", 10)
# Set axis label style to 8pts Arial Bold
c.xAxis().setLabelStyle("simsun.ttc", 8)
c.yAxis().setLabelStyle("simsun.ttc", 8)
# Set axis line width to 2 pixels
c.xAxis().setWidth(2)
c.yAxis().setWidth(2)
# Output the chart
c.makeChart("1.png")
- 大小: 9.9 KB
- 大小: 14.1 KB
分享到:
相关推荐
主要介绍了PIL图像处理模块paste方法简单使用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
今天用到了img.paste函数,就写篇笔记记录一下,方便回顾。 做人脸检测,产生负样本的时候想把图片中人连部分用背景的某一部分替换掉,然后再随机裁剪产生负样本,这样比随机裁剪的时候避开人脸区域应该实现起来更...
SSIM-PIL 使用结构相似性算法(SSIM)比较两个图像。 对于相同的图像,结果值在1.0和完全不同的图像之间为0.0。 它基于PIL,还通过pyopencl支持GPU加速。安装python3 -m pip install SSIM-PIL 确保安装pyopencl的...
使用到 PIL 模块中的函数: Image.open :打开一张图片,获取 Image 对象。 Image.convert(mode='L') :将图片转为灰度图像 Image.crop :截取图片中的一块区域 Image.paste :将另外一张图片粘贴到当前图片中 Image...
主要为大家详细介绍了python使用PIL剪切和拼接图片,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
PIL最新版中文手册。涵盖PIL全部函数的使用说明。
在网络资源的基础上增加了标签,更便于查看,阅读;
python验证码识别所需要的Pil和pytesser打包下载。适用于使用python以及工具包进行简单的验证码识别
Python中使用PIL快速实现二值图代码与资源,
Python PIL1.1.7 模块Python PIL1.1.7 模块Python PIL1.1.7 模块Python PIL1.1.7 模块Python PIL1.1.7 模块Python PIL1.1.7 模块Python PIL1.1.7 模块Python PIL1.1.7 模块Python PIL1.1.7 模块Python PIL1.1.7 模块...
结合帖子中的需求,对局部进行高斯模糊,所以还需要结合使用 crop 和 paste 方法实现局部使用滤镜。 代码如下: #-*- coding: utf-8 -*- from PIL import Image, ImageFilter class MyGaussianBlur(ImageFilter....
Python Image Library 中文手册,官方文档,涵盖PIL全部函数的使用说明。
PIL 和pillow图像处理模块安装说明,及其部分异常处理。
在使用openalpr的时候需要用python,发现总是少了PIL modle ,所以这里有一个配套的PIL安装包,适用于windows。先安装python2.6然后再安装PIL
PIL python 2.7 win64 ,pil没有64位版本,这个是64位的。
python使用PIL库读取图片的像素值.
python下的PIL模块支持的字体文件
主要介绍了使用Python的PIL模块来进行图片对比的方法,搜索引擎最基本的图片搜索也是利用图片颜色值的对比来实现的,需要的朋友可以参考下