~ubuntu-branches/ubuntu/saucy/lazygal/saucy

« back to all changes in this revision

Viewing changes to lazygal/eyecandy.py

  • Committer: Package Import Robot
  • Author(s): Michal Čihař
  • Date: 2011-11-16 13:18:57 UTC
  • mto: (2.1.13 sid) (1.1.9)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: package-import@ubuntu.com-20111116131857-0zradjz1me752vhg
Import upstream version 0.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
class PictureMess:
29
29
 
30
 
    RESULT_SIZE = (200, 150)
31
30
    STEP = 5
32
31
    THUMB_HOW_MANY = 5
33
32
    THUMB_MAX_ROTATE_ANGLE = 40
34
 
    THUMB_SIZE = [3*max(RESULT_SIZE)//5 for i in range(2)]
35
33
    THUMB_WHITE_WIDTH = 5
36
34
 
37
 
    def __init__(self, images_paths, top_image_path=None, bg='transparent'):
 
35
    def __init__(self, images_paths, top_image_path=None, bg='transparent',
 
36
                 result_size=(200, 150, )):
38
37
        if len(images_paths) > self.THUMB_HOW_MANY:
39
38
            self.images_paths = random.sample(images_paths, self.THUMB_HOW_MANY)
40
39
        else:
51
50
 
52
51
        self.bg = bg != 'transparent' and bg or Color.TRANSPARENT
53
52
 
 
53
        self.result_size = result_size
 
54
        self.thumb_size = [3*max(self.result_size)//5 for i in range(2)]
 
55
 
54
56
        self.picture_mess = None
55
57
 
56
58
    def __build_mess_thumb(self, image_path):
57
59
        img = Image.open(image_path)
58
 
        img.thumbnail(self.THUMB_SIZE, Image.ANTIALIAS)
 
60
        img.thumbnail(self.thumb_size, Image.ANTIALIAS)
59
61
 
60
62
        white_size = [ x + 2*self.THUMB_WHITE_WIDTH for x in img.size ]
61
63
 
74
76
        thumb = thumb.rotate(rotation, resample=Image.BILINEAR)
75
77
 
76
78
        thumb = thumb.crop(thumb.getbbox())
77
 
        thumb.thumbnail(self.THUMB_SIZE, Image.ANTIALIAS)
 
79
        thumb.thumbnail(self.thumb_size, Image.ANTIALIAS)
78
80
        return thumb
79
81
 
80
82
    def __rand_coord_with_step(self, coord, holding_coord):
112
114
        self.__paste_img_to_mess_top(img, self.__place_thumb_box(img))
113
115
 
114
116
    def __build_picture_mess(self):
115
 
        self.picture_mess = Image.new("RGBA", self.RESULT_SIZE)
 
117
        self.picture_mess = Image.new("RGBA", self.result_size)
116
118
        added_one_thumb = False
117
119
        for image_path in self.images_paths:
118
120
            try: