Exemple #1
0
def test_has_transparency_rgba_transparency():
    image = __load_image("rgba_icon_transparency.png")
    assert has_transparency(image) is True
Exemple #2
0
def _check_image_type(error_counter, image_type, addon_xml, addon_path):
    images = addon_xml.findall("*//" + image_type)

    icon_fallback = False
    fanart_fallback = False
    if not images and image_type == "icon":
        icon_fallback = True
        image = type('image', (object, ), {'text': 'icon.png'})()
        images.append(image)
    elif not images and image_type == "fanart":
        skip_addon_types = [".module.", "metadata.", "context.", ".language."]
        for addon_type in skip_addon_types:
            if addon_type in addon_path:
                break
        else:
            fanart_fallback = True
            image = type('image', (object, ), {'text': 'fanart.jpg'})()
            images.append(image)

    for image in images:
        if image.text:
            filepath = os.path.join(addon_path, image.text)
            if os.path.isfile(filepath):
                print("Image %s exists" % image_type)
                try:
                    im = Image.open(filepath)
                    width, height = im.size

                    if image_type == "icon":
                        if has_transparency(im):
                            error_counter = _logProblem(
                                error_counter,
                                "Icon.png should be solid. It has transparency."
                            )
                        if (width != 256
                                and height != 256) and (width != 512
                                                        and height != 512):
                            error_counter = _logProblem(
                                error_counter,
                                "Icon should have either 256x256 or 512x512 but it has %sx%s"
                                % (width, height))
                        else:
                            print("%s dimensions are fine %sx%s" %
                                  (image_type, width, height))
                    elif image_type == "fanart":
                        fanart_sizes = [(1280, 720), (1920, 1080),
                                        (3840, 2160)]
                        fanart_sizes_str = " or ".join(
                            ["%dx%d" % (w, h) for w, h in fanart_sizes])
                        if (width, height) not in fanart_sizes:
                            error_counter = _logProblem(
                                error_counter,
                                "Fanart should have either %s but it has %sx%s"
                                % (fanart_sizes_str, width, height))
                        else:
                            print("%s dimensions are fine %sx%s" %
                                  (image_type, width, height))
                    else:
                        # screenshots have no size definitions
                        pass
                except IOError:
                    error_counter = _logProblem(
                        error_counter,
                        "Could not open image, is the file corrupted? %s" %
                        relative_path(filepath))

            else:
                # if it's a fallback path addons.xml should still be able to
                # get build
                if fanart_fallback or icon_fallback:
                    if icon_fallback:
                        print("You might want to add a icon")
                    elif fanart_fallback:
                        print("You might want to add a fanart")
                # it's no fallback path, so building addons.xml will crash -
                # this is a problem ;)
                else:
                    error_counter = _logProblem(
                        error_counter,
                        "%s does not exist at specified path." % image_type)
        else:
            error_counter = _logWarning(
                error_counter, "Empty image tag found for %s" % image_type)
    return error_counter
Exemple #3
0
def test_has_transparency_rgba():
    image = __load_image("rgba_icon.png")
    assert has_transparency(image) is False