2012-05-18 16 views
37

मैं पीआईएल से परिचित नहीं हूं, लेकिन मुझे पता है कि छवि मैगिक में ग्रिड में छवियों का एक समूह डालना बहुत आसान है।आप पीआईएल/तकिया का उपयोग कर छवियों को कैनवास में कैसे मर्ज करते हैं?

उदाहरण के लिए, मैं 16 छवियों को 4 × 4 ग्रिड में कैसे डालूं जहां मैं पंक्तियों और स्तंभों के बीच अंतर निर्दिष्ट कर सकता हूं?

उत्तर

67

यह PIL में भी करना आसान है। एक खाली छवि बनाएं और paste का उपयोग करके आपको जो भी पदों की आवश्यकता है, उस छवियों में बस पेस्ट करें।

import Image 

#opens an image: 
im = Image.open("1_tree.jpg") 
#creates a new empty image, RGB mode, and size 400 by 400. 
new_im = Image.new('RGB', (400,400)) 

#Here I resize my opened image, so it is no bigger than 100,100 
im.thumbnail((100,100)) 
#Iterate through a 4 by 4 grid with 100 spacing, to place my image 
for i in xrange(0,500,100): 
    for j in xrange(0,500,100): 
     #I change brightness of the images, just to emphasise they are unique copies. 
     im=Image.eval(im,lambda x: x+(i+j)/30) 
     #paste the image at location i,j: 
     new_im.paste(im, (i,j)) 

new_im.show() 

enter image description here

: यहाँ एक त्वरित उदाहरण है
संबंधित मुद्दे