[Image-SIG] PIL how to display multiple images side by side
Suresh Kumar
suresh.amritapuri at gmail.com
Mon Jan 11 21:26:47 CET 2010
Is there any way I can force the images to stay? the following is the code
that I have adapted from somewhere for this purpose.
Thanks
suresh
----------------beginning of code--------------------
def button_click_exit_mainloop (event):
event.widget.quit() # this will cause mainloop to unblock.
root = Tkinter.Tk()
root.bind("<Button>", button_click_exit_mainloop)
root.geometry('+%d+%d' % (100,100))
names = ["me1.jpg","me2.jpg","me1.jpg","me2.jpg","me1.jpg","me2.jpg"]
shape = (2,3)
xlen,ylen = 0,0
for i in range(shape[0]):
for j in range(shape[1]):
try:
images = [Image.open(f) for f in names]
images = [x.resize((300,200)) for x in images]
xsize = sum(im.size[0] for im in images)
ysize = sum(im.size[1] for im in images)
root.geometry('%dx%d' % (xsize,ysize))
tkpi = [ImageTk.PhotoImage(im) for im in images]
index = i*shape[1]+j
label_image = Tkinter.Label(root, image=tkpi[index])
label_image.place(x=xlen,y=ylen,width=images[index].size[0],height=images[index].size[1])
if j == shape[1]-1:
ylen = ylen + images[index].size[1]
xlen = 0
else:
xlen = xlen + images[index].size[0]
print index,xlen,ylen
root.mainloop() # wait until user clicks the window
except Exception, e:
# This is used to skip anything not an image.
# Image.open will generate an exception if it cannot open a file.
# Warning, this will hide other errors as well.
pass
-------------------------- end of code ------------------
On Fri, Jan 8, 2010 at 3:00 PM, Edward Cannon <cannon.el at gmail.com> wrote:
>
> Manually make a composite image using the paste() function or simillar and
> then display that one image.
>
>
>
> On Jan 8, 2010, at 1:43 PM, Suresh Kumar <suresh.amritapuri at gmail.com>
> wrote:
>
> Hi,
>>
>> In PIL, how to display multiple images in say m rows and n colums when
>> I have m*n images.
>>
>> suresh
>>
>>
>> --
>> R Suresh Kumar,
>> Phd Student, Vislab
>> EE, Univ. of California
>> Riverside, CA 92507
>> --
>> Even after all this time The sun never says to the earth, "You owe Me."
>> Look what happens with A love like that, It lights the Whole Sky.
>> - Hafiz e Shirazi
>> _______________________________________________
>> Image-SIG maillist - Image-SIG at python.org
>> http://mail.python.org/mailman/listinfo/image-sig
>>
> _______________________________________________
> Image-SIG maillist - Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>
--
R Suresh Kumar,
Phd Student, Vislab
EE, Univ. of California
Riverside, CA 92507
--
Even after all this time The sun never says to the earth, "You owe Me."
Look what happens with A love like that, It lights the Whole Sky.
- Hafiz e Shirazi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20100111/428f09d7/attachment-0001.htm>
More information about the Image-SIG
mailing list