Exemple #1
0
 def testLandscapeCrop(self):
     def mean_pixel(x, y):
         values = im.getpixel((x, y))
         if not isinstance(values, (tuple, list)):
             values = [values]
         return reduce(operator.add, values) / len(values)
     for crop in ('center', '50% 200%', '50px 700px'):
         th = self.backend.get_thumbnail(self.landscape, '100x100', crop=crop)
         engine = EnginePil()
         im = engine.get_image(th)
         self.assertEqual(mean_pixel(0, 50), 255)
         self.assertEqual(mean_pixel(45, 50), 255)
         self.assertEqual(250 < mean_pixel(49, 50) <= 255, True)
         self.assertEqual(mean_pixel(55, 50), 0)
         self.assertEqual(mean_pixel(99, 50), 0)
     for crop in ('left', '0%', '0px'):
         th = self.backend.get_thumbnail(self.landscape, '100x100', crop=crop)
         engine = EnginePil()
         im = engine.get_image(th)
         for x in xrange(0, 99, 10):
             for y in xrange(0, 99, 10):
                 self.assertEqual(250 < mean_pixel(x, y) <= 255, True)
     for crop in ('right', '100%', '100px'):
         th = self.backend.get_thumbnail(self.landscape, '100x100', crop=crop)
         engine = EnginePil()
         im = engine.get_image(th)
         for x in xrange(0, 99, 10):
             for y in xrange(0, 99, 10):
                 self.assertEqual(0 <= mean_pixel(x, y) < 5, True)
Exemple #2
0
 def testPortraitCrop(self):
     def mean_pixel(x, y):
         values = im.getpixel((x, y))
         if not isinstance(values, (tuple, list)):
             values = [values]
         return reduce(operator.add, values) / len(values)
     for crop in ('center', '88% 50%', '50px'):
         th = self.backend.get_thumbnail(self.portrait, '100x100', crop=crop)
         engine = EnginePil()
         im = engine.get_image(th)
         self.assertEqual(mean_pixel(50,0), 255)
         self.assertEqual(mean_pixel(50,45), 255)
         self.assertEqual(250 < mean_pixel(50,49) <= 255, True)
         self.assertEqual(mean_pixel(50,55), 0)
         self.assertEqual(mean_pixel(50,99), 0)
     for crop in ('top', '0%', '0px'):
         th = self.backend.get_thumbnail(self.portrait, '100x100', crop=crop)
         engine = EnginePil()
         im = engine.get_image(th)
         for x in xrange(0, 99, 10):
             for y in xrange(0, 99, 10):
                 self.assertEqual(250 < mean_pixel(x, y) <= 255, True)
     for crop in ('bottom', '100%', '100px'):
         th = self.backend.get_thumbnail(self.portrait, '100x100', crop=crop)
         engine = EnginePil()
         im = engine.get_image(th)
         for x in xrange(0, 99, 10):
             for y in xrange(0, 99, 10):
                 self.assertEqual(0 <= mean_pixel(x, y) < 5, True)