~canonical-platform-qa/ubuntu-system-tests/snap-channel-support

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/helpers/images.py

  • Committer: Santiago Baldassin
  • Date: 2017-02-20 19:49:08 UTC
  • mfrom: (495.1.16 trunk)
  • Revision ID: santiago.baldassin@canonical.com-20170220194908-yn7p71t4rzxj3idy
MErgeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
2
#
3
3
# Ubuntu System Tests
4
 
# Copyright (C) 2015 Canonical
 
4
# Copyright (C) 2015-2017 Canonical
5
5
#
6
6
# This program is free software: you can redistribute it and/or modify
7
7
# it under the terms of the GNU General Public License as published by
25
25
import subprocess
26
26
 
27
27
 
28
 
def get_colour_count(image_path):
29
 
    """Return the number of colours in the specified image."""
 
28
def get_color_count(image_path):
 
29
    """Return the number of colors in the specified image."""
30
30
    img = Image.open(image_path)
31
 
    # get a list of colours from total number of pixels in the image
 
31
    # get a list of colors from total number of pixels in the image
32
32
    colours = img.getcolors(img.size[0] * img.size[1])
33
33
    return len(colours)
34
34
 
35
35
 
 
36
def get_color_percentage(image_path, threshold):
 
37
    """Return percentage value of pixels which fall under threshold level."""
 
38
    img = Image.open(image_path)
 
39
    black_pixels = 0
 
40
    for color in img.getcolors(img.size[0]*img.size[1]):
 
41
        if hasattr(color[1], 'count'):
 
42
            # This is a tuple or list
 
43
            color_ave = sum(color[1]) // len(color[1])
 
44
        else:
 
45
            color_ave = color[1]
 
46
        if color_ave <= threshold:
 
47
            black_pixels += color[0]
 
48
    return (black_pixels / (img.size[0] * img.size[1])) * 100
 
49
 
 
50
 
36
51
def _get_exiftool_value(image_path, *values):
37
52
    """ Return the exittool value of the picture """
38
53
    result = subprocess.check_output(['exiftool', image_path] + list(values) +