个人签名设计网站,企业网站html模板,wordpress中常用插件安装包,wordpress模板上传不PIL(Python Imaging Library)是python语言中对图像处理方面的一个开源库#xff0c;其主要功能模块为Image#xff0c;对于Image模块#xff0c;可以使用from PIL import Image或者import Image由于使用了试用版的chartdir库#xff0c;在生成图片的时候下面会出现一行提示…PIL(Python Imaging Library)是python语言中对图像处理方面的一个开源库其主要功能模块为Image对于Image模块可以使用from PIL import Image或者import Image由于使用了试用版的chartdir库在生成图片的时候下面会出现一行提示是非注册版的文字看起来不太舒服。如所以想使用PIL自动地将下面一行去掉查阅了一下PIL的文档最后决定使用PIL的crop和paste函数实现功能实现的代码如下import Imageimport sysif len(sys.argv)2:print %s % __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/pythonfrom pychartdir import *# The data for the bar chartdata [450, 560, 630, 800, 1100, 1350, 1600, 1950, 2300, 2700, 3200, 3800]# The labels for the bar chartlabels [一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月,十月, 十一月, 十二月]# Create a XYChart object of size 600 x 360 pixelsc XYChart(600, 360)# Add a title to the chart using 18pts Times Bold Italic fontc.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 labelsc.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 fontc.yAxis().setTitle(人民币 (元), simsun.ttc, 10)# Set axis label style to 8pts Arial Boldc.xAxis().setLabelStyle(simsun.ttc, 8)c.yAxis().setLabelStyle(simsun.ttc, 8)# Set axis line width to 2 pixelsc.xAxis().setWidth(2)c.yAxis().setWidth(2)# Output the chartc.makeChart(1.png)大小: 9.9 KB 大小: 14.1 KB2顶0踩分享到 2009-04-07 00:07浏览 31865评论