phaigeim
phaigeim

Reputation: 749

Drawing multiple Images to a tiff file in python

I have same size of multiple images and I want to draw those images on a tiff file in such a way that there should be less than 5 elements in a row with some x distance (horizontally along the row) between its centres and y distance (vertically along the column) The images are stored in a folder, the program should read images and draw images on tiff file.

I found this as somewhat useful (and nearer to what i require) http://www.astrobetter.com/plotting-to-a-file-in-python/ But it is plotting a graph to file. I want to put images to my tiff file

How should I proceed?

Upvotes: 1

Views: 1912

Answers (1)

carlosdc
carlosdc

Reputation: 12152

This is what you describe, I think. Here is the image, you can have many of them as long as they're all the same size, configure the values on the images list in the code to change this.

enter image description here

and this is the output of the program:

enter image description here

and here is the code:

import Image

images = ['image.jpg','image.jpg','image.jpg','image.jpg','image.jpg','image.jpg','image.jpg']

hsize = min(5,len(images))
vsize = (len(images)/5) + 1

print hsize,vsize

vspace = 10
hspace = 10

(h,w) = Image.open(images[0]).size

im = Image.new('RGB',((hsize*(h+hspace)),(vsize*(w+vspace)) ))

for i,filename in enumerate(images):
    imin = Image.open(filename).convert('RGB')
    xpos = i % hsize
    ypos = i / hsize
    print xpos,ypos
    im.paste(imin,(xpos*(h+hspace),ypos*(w+vspace)))
im.save('output.jpg')

Upvotes: 2

Related Questions