日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

python中paste函数的作用_PIL使用小结(crop和paste函数)

發(fā)布時(shí)間:2024/10/8 python 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python中paste函数的作用_PIL使用小结(crop和paste函数) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

PIL(Python Imaging Library)是python語(yǔ)言中對(duì)圖像處理方面的一個(gè)開源庫(kù),其主要功能模塊為Image,對(duì)于Image模塊,可以使用

from PIL import Image

或者

import Image

由于使用了試用版的chartdir庫(kù),在生成圖片的時(shí)候下面會(huì)出現(xiàn)一行提示是非注冊(cè)版的文字,看起來(lái)不太舒服。

所以想使用PIL自動(dòng)地將下面一行去掉,查閱了一下PIL的文檔,最后決定使用PIL的crop和paste函數(shù)實(shí)現(xiàn)功能

實(shí)現(xiàn)的代碼如下:

import Image

import sys

if 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()

這可以使用的方法有兩種,第一種是以及被注釋掉的方法,即生成一個(gè)新的Image,調(diào)用Image.new方法。然后將該image粘貼到需要修改的圖片上。另外一種為了保持圖片的前后背景色一致,從圖片的最前頭拷貝一部分圖片(使用crop函數(shù)),然后在粘貼到需要修改的圖片上,來(lái)完成最下端文字的覆蓋。

crop函數(shù)帶的參數(shù)為(起始點(diǎn)的橫坐標(biāo),起始點(diǎn)的縱坐標(biāo),寬度,高度)

paste函數(shù)的參數(shù)為(需要修改的圖片,粘貼的起始點(diǎn)的橫坐標(biāo),粘貼的起始點(diǎn)的縱坐標(biāo))

下面是處理結(jié)果之后的圖片:

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")

總結(jié)

以上是生活随笔為你收集整理的python中paste函数的作用_PIL使用小结(crop和paste函数)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。