2013-04-16 26 views
0

我已經爲使用python的四個單獨的劇情編寫腳本。也出於某種原因,我想將所有四個組合到一個單一的panel.I想創建一個模板。 如何創建模板以使用python在單個面板中顯示四個圖?如何在使用python的單個面板中創建四個圖的模板?

import cdms2,vcs,cdutil,cdtime,os,sys,time 
f=cdms2.open('/home/alagu/Desktop/data/1xco2.cam2.h0.0001-01.nc') 
data=f('Z3')  
v=vcs.init() 
v.plot(data) 
v.gs('Z3.jpg',device='jpeg', orientation='p') 

謝謝

回答

0

可以使用Python Imaging Library

  • 創建一個空白圖像,它至少是由vcs創建的最大圖的寬度和高度的兩倍。
  • 然後加載vcs產生的圖像並將它們粘貼到空白圖像中。
  • 將新映像寫入磁盤。

像這樣:

from PIL import Image 

srcs = [] 
srcs.append(Image.open('Z1.jpg')) 
srcs.append(Image.open('Z2.jpg')) 
srcs.append(Image.open('Z3.jpg')) 
srcs.append(Image.open('Z4.jpg')) 

xoffs = max([i.size[0] for i in srcs]) 
yoffs = max([i.size[0] for i in srcs]) 

combined = Image.new('RGBA', (2*xoffs, 2*yoffs)) 

combined.paste(srcs[0], (0,0)) 
combined.paste(srcs[1], (xoffs,0)) 
combined.paste(srcs[2], (0,yoffs)) 
combined.paste(srcs[3], (xoffs,yoffs)) 

combined.write('combined.jpg') 
相關問題