Re: PIL how to display multiple images side by side

Suresh Kumar <[email protected]>
Newsgroups gmane.comp.python.image
Message-ID <[email protected]>
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 <[email protected]> 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 <[email protected]>
> 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  -  [email protected]
>> http://mail.python.org/mailman/listinfo/image-sig
>>
> _______________________________________________
> Image-SIG maillist  -  [email protected]
> 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

_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.