Changeset 15

Show
Ignore:
Timestamp:
09/24/07 11:19:31 (1 year ago)
Author:
steve
Message:

Nicer thumbnail generation. Now all thumbnails are crop_size x crop_size

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mactorii.py

    r14 r15  
    101101                        xmotion*=2       
    102102 
    103         if symbol == key.D and hovering_over != None: 
    104                 assert images.has_key(hovering_over) 
    105                 del images[hovering_over] 
    106                 update_renderables() 
    107                 shutil.move(hovering_over, "%s/%s"%(config.trash_dir, os.path.basename(hovering_over))) 
    108                 last_deleted.append(hovering_over) 
     103        if hovering_over != None: 
     104                if symbol == key.D: 
     105                        assert images.has_key(hovering_over) 
     106                        del images[hovering_over] 
     107                        update_renderables() 
     108                        shutil.move(hovering_over, "%s/%s"%(config.trash_dir, os.path.basename(hovering_over))) 
     109                        last_deleted.append(hovering_over) 
    109110                 
    110111        if symbol == key.U and len(last_deleted) > 0: 
     
    118119                        fps_display = None 
    119120                else: 
    120                         fps_display = clock.ClockDisplay() 
    121                          
     121                        fps_display = clock.ClockDisplay()               
    122122def strip_width(): 
    123123        """returns the width of the strip in pixels""" 
     
    172172        wi = wavelet.open(file) 
    173173        sig = wi.signature() 
    174         wi.im.thumbnail((config.crop_size, config.crop_size), Image.ANTIALIAS) 
    175         wi.im = wi.im.transpose(Image.FLIP_TOP_BOTTOM) 
    176         psurf=pyglet_image.ImageData(wi.im.size[0],wi.im.size[1],"RGB",wi.im.tostring()) 
    177  
     174         
     175        # resize the image so the smallest dimension is config.crop_size 
     176        im = wi.im 
     177        w,h = im.size 
     178        s=0 
     179        if w > h: 
     180                s = 1.0*config.crop_size/h 
     181        else: 
     182                s = 1.0*config.crop_size/w 
     183         
     184        w = int(w*s) 
     185        h = int(h*s)     
     186         
     187        im.thumbnail((w, h), Image.ANTIALIAS) 
     188         
     189         
     190        # crop out the centre crop_size square to use a thumbnail 
     191        midx = w/2 
     192        midy = h/2 
     193                 
     194        box = (midx-config.crop_size/2, midy-config.crop_size/2, midx+config.crop_size/2, midy+config.crop_size/2) 
     195        im=im.crop(box) 
     196         
     197        # make a pyglet image out of it 
     198        im = im.transpose(Image.FLIP_TOP_BOTTOM) 
     199        psurf=pyglet_image.ImageData(im.size[0],im.size[1],"RGB",im.tostring()) 
     200         
     201        # add to our dictionary 
    178202        images[ unicode(file,'utf-8').encode('ascii', 'ignore') ] = (psurf, None, sig, wi.size) 
    179203         
     
    288312                        if is_over_image(x,y,hoverx, hovery): 
    289313                                #pix_name =     font.Text(ft, filename, hoverx, hovery+config.font_size+5) 
    290                                 pix_size = font.Text(ft, "%dx%d"%(image[3][0], image[3][0]), x+config.crop_size/2, y, halign=font.Text.CENTER) 
     314                                pix_size = font.Text(ft, "%dx%d"%(image[3][0], image[3][0]), x+config.crop_size/2, y+3, halign=font.Text.CENTER) 
    291315                                pix_size.color = (1,1,1,1) 
    292316                                text_bg = image_pattern.create_image(config.crop_size, int(pix_size.height)     )