本文實(shí)例為大家分享了python生成圓形圖片的具體代碼,供大家參考,具體內(nèi)容如下
# -*- coding: utf-8 -*- """ __author__= 'Du' __creation_time__= '2018/1/5 9:08' """  import os, math from PIL import Image   def circle():  ima = Image.open("ball1.jpg").convert("RGBA")  # ima = ima.resize((600, 600), Image.ANTIALIAS)  size = ima.size  print(size)   # 因?yàn)槭且獔A形,所以需要正方形的圖片  r2 = min(size[0], size[1])  if size[0] != size[1]:   ima = ima.resize((r2, r2), Image.ANTIALIAS)   # 最后生成圓的半徑  r3 = 60  imb = Image.new('RGBA', (r3*2, r3*2),(255,255,255,0))  pima = ima.load() # 像素的訪問對(duì)象  pimb = imb.load()  r = float(r2/2) #圓心橫坐標(biāo)   for i in range(r2):   for j in range(r2):    lx = abs(i-r) #到圓心距離的橫坐標(biāo)    ly = abs(j-r)#到圓心距離的縱坐標(biāo)    l = (pow(lx,2) + pow(ly,2))** 0.5 # 三角函數(shù) 半徑     if l < r3:     pimb[i-(r-r3),j-(r-r3)] = pima[i,j]  imb.save("test_circle.png")  circle() 效果圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林站長(zhǎng)站。
新聞熱點(diǎn)
疑難解答
圖片精選