Beispiel #1
0
def modify_images(application_path):
    output_dirs = [
        path.join(application_path, "..", "512"),
        path.join(application_path, "..", "150")
    ]
    count_files = 0
    override = None

    FileUtilities.create_needed_folder(output_dirs)

    print()
    print(
        "\t--------------------------------------------------------------------"
    )
    print()
    print("\tErstelle die Bilder in der Größe \"512px\":")
    print()

    for filename in listdir(application_path):
        if not filename.endswith(".jpg"):
            continue

        if path.isfile(path.join(output_dirs[0], filename)):
            if override is None:
                override = TerminalUtilities.query_yes_no(
                    "\tSollen die bereits vorhandenen Bilder überschrieben werden?",
                    False)

            if not override:
                continue

        try:
            img = Image(path.join(application_path, filename))
            # noinspection PyArgumentList
            img.strip()
            # noinspection PyArgumentList
            img.trim()
            img.quality(80)
            img.resize("512x512>")
            img.write(path.join(output_dirs[0], filename))
        except RuntimeError as error:
            TerminalUtilities.error_handler(str(error), "RuntimeError")

        print("\t" + filename + "\t erfolgreich erstellt.")

        count_files += 1

    print()
    print("\tInsgesamt wurden " + str(count_files) +
          " Bilder in der Größe \"512px\" erzeugt.")
    print()
    print(
        "\t--------------------------------------------------------------------"
    )
    print()
    print("\tErstelle die Bilder in der Größe \"150px\":")
    print()

    count_files = 0

    for filename in listdir(output_dirs[0]):
        if not filename.endswith(".jpg"):
            continue

        if (not override) and (path.isfile(path.join(output_dirs[1],
                                                     filename))):
            continue

        img = Image(path.join(output_dirs[0], filename))
        img.resize("150x150>")
        img.write(path.join(output_dirs[1], filename))

        print("\t" + filename + "\t erfolgreich erstellt.")

        count_files += 1

    print()
    print("\tInsgesamt wurden " + str(count_files) +
          " Bilder in der Größe \"150px\" erzeugt.")