Ejemplo n.º 1
0
def process_image(image_tag):
    name = get_filename(image_tag['src'])
    global i, image_nr
    i = i + 1
    complete = floor(100.0 * i / image_nr)
    print(f'[STEP] Getting data for image {name:s}\n[PROGRESS] {complete:d}')

    # Force absolute URLs.
    image_tag['src'] = urljoin(siteurl, image_tag['src'])
    # Get image size.
    image = urlopen(image_tag['src'], context=sslctx)
    image_res = Image.open(image)

    return {
        'name': name,
        'src': image_tag['src'],
        'alt': image_tag['alt'],
        'width': image_res.size[0],
        'height': image_res.size[1],
        'format': image_res.format,
        'size': image.headers['content-length'],
        'brightness': get_brightness(image_res)
    }
Ejemplo n.º 2
0
 def test_no_path(self):
     path = None
     with self.assertRaises(TypeError) as cm:
         luminosity.get_brightness(path)
     self.assertEqual(cm.exception.message, "File path must be provided.")
Ejemplo n.º 3
0
 def test_gif(self):
     path = os.path.join(self.fixtures_path, 'aguilera.gif')
     self.assertEqual(luminosity.get_brightness(path), 43.562)
Ejemplo n.º 4
0
 def test_not_image(self):
     path = __file__
     with self.assertRaises(IOError):
         luminosity.get_brightness(path)
Ejemplo n.º 5
0
 def test_unreadable(self):
     path = os.path.join(self.fixtures_path, 'nonsense.png')
     with self.assertRaises(IOError):
         luminosity.get_brightness(path)
Ejemplo n.º 6
0
    def test_blue(self):
        path = os.path.join(self.fixtures_path, 'blue.png')
        self.assertEqual(luminosity.get_brightness(path), 18.411)

        path = os.path.join(self.fixtures_path, 'blue_with_transparency.png')
        self.assertEqual(luminosity.get_brightness(path), 18.411)
Ejemplo n.º 7
0
    def test_green(self):
        path = os.path.join(self.fixtures_path, 'green.png')
        self.assertEqual(luminosity.get_brightness(path), 182.376)

        path = os.path.join(self.fixtures_path, 'green_with_transparency.png')
        self.assertEqual(luminosity.get_brightness(path), 182.376)
Ejemplo n.º 8
0
    def test_red(self):
        path = os.path.join(self.fixtures_path, 'red.png')
        self.assertEqual(luminosity.get_brightness(path), 54.213)

        path = os.path.join(self.fixtures_path, 'red_with_transparency.png')
        self.assertEqual(luminosity.get_brightness(path), 54.213)
Ejemplo n.º 9
0
 def test_transparent(self):
     path = os.path.join(self.fixtures_path, 'transparent.png')
     self.assertEqual(luminosity.get_brightness(path), 0.0)
Ejemplo n.º 10
0
    def test_black(self):
        path = os.path.join(self.fixtures_path, 'black.png')
        self.assertEqual(luminosity.get_brightness(path), 0.0)

        path = os.path.join(self.fixtures_path, 'black_with_transparency.png')
        self.assertEqual(luminosity.get_brightness(path), 0.0)
Ejemplo n.º 11
0
    def test_white(self):
        path = os.path.join(self.fixtures_path, 'white.png')
        self.assertEqual(luminosity.get_brightness(path), 255.0)

        path = os.path.join(self.fixtures_path, 'white_with_transparency.png')
        self.assertEqual(luminosity.get_brightness(path), 255.0)