Exemple #1
0
def slants(side, show, name, swirl, set_wall, gradient, invert):
    """Generates slanting lines of various colors"""

    error = ""
    if side < 50:
        error = "Image too small. Minimum size 50"

    if error:
        logger.error(error)
        click.secho(error, fg="red", err=True)
        sys.exit(1)

    scale = 2
    side = side * scale  # increase size to anti alias
    print("Preparing image", end="")

    img = drawSlants(side, gradient, invert)

    print("\r", end="")
    print("Making final tweaks", end="")
    img = img.resize((side // scale, side // scale), resample=Image.BICUBIC)

    if swirl:
        img = swirl_image(img, swirl)

    if show:
        img.show()

    file_name = ""

    if name:
        file_name = f"{name}.png"
        img.save(file_name)
    else:
        file_name = f"wall-{int(time.time())}.png"
        img.save(file_name)

    print("\r", end="")
    print(f"Image is stored at {file_name}")
    if set_wall:
        msg, ret = setwallpaper(file_name)
        if ret:
            click.secho(msg, fg="green")
        else:
            logger.error(msg)
            click.secho(msg, fg="red")
Exemple #2
0
def slants(side, show, name, swirl, set_wall):
    """ Generates slanting lines of various colors """

    scale = 2
    side = side * scale  # increase size to anti alias
    print("Preparing image", end="")

    img = drawSlants(side)

    print("\r", end="")
    print("Making final tweaks", end="")
    img = img.resize((side // scale, side // scale), resample=Image.BICUBIC)

    if swirl:
        img = swirl_image(img, swirl)

    if show:
        img.show()

    file_name = ""

    if name:
        file_name = "{}.png".format(name)
        img.save(file_name)
    else:
        file_name = "wall-{}.png".format(int(time.time()))
        img.save(file_name)

    print("\r", end="")
    print(f"Image is stored at {file_name}")
    if set_wall:
        msg, ret = setwallpaper(file_name)
        if ret:
            click.secho(msg, fg="green")
        else:
            click.secho(msg, fg="red")
Exemple #3
0
def pic_shape(image, shape, show, outline, name, percent, set_wall):
    """Generate a HQ image of a beautiful shapes"""
    error = None
    if percent:
        if percent < 1 or percent > 10:
            error = "Percent range 1-10"

    if error:
        logger.error(error)
        click.secho(error, fg="red", err=True)
        sys.exit(1)

    img = Image.open(image)

    width = img.width
    height = img.height

    if outline:
        if isinstance(outline, tuple):
            pass
        else:
            try:
                outline = tuple(bytes.fromhex(outline[1:]))
            except Exception as e:
                logger.error(type(e).__name__)
                logger.error(e)
                click.secho("Invalid color hex", fg="red", err=True)
                sys.exit(1)

    print("Preparing image", end="")

    if shape == "hex":
        percent = percent if percent else 5
        img = genHexagon(width, height, img, outline, pic=True, per=percent)
    elif shape == "sq":
        img = genSquares(width, height, img, outline, pic=True, per=percent)
    elif shape == "dia":
        img = genDiamond(width, height, img, outline, pic=True, per=percent)
    elif shape == "tri":
        img = genTriangle(width, height, img, outline, pic=True, per=percent)
    elif shape == "iso":
        img = genIsometric(width, height, img, outline, pic=True, per=percent)
    else:
        error = """
        No shape given. To see list of shapes \"wallgen pic shape --help\"
        """
        logger.error(error)
        click.secho(error, fg="red", err=True)
        sys.exit(1)

    print("\r", end="")
    print("Making final tweaks", end="")

    if show:
        img.show()

    file_name = ""

    if name:
        file_name = f"{name}.png"
        img.save(file_name)
    else:
        file_name = f"wall-{int(time.time())}.png"
        img.save(file_name)

    print("\r", end="")
    print(f"Image is stored at {file_name}")
    if set_wall:
        msg, ret = setwallpaper(file_name)
        if ret:
            click.secho(msg, fg="green")
        else:
            logger.error(msg)
            click.secho(msg, fg="red")
Exemple #4
0
def pic_poly(image, points, show, outline, name, smart, set_wall):
    """Generates a HQ low poly image"""

    if points < MIN_POINTS:
        error = f"Too less points. Minimum points {MIN_POINTS}"
    elif points > MAX_POINTS:
        error = f"Too many points. Maximum points {MAX_POINTS}"
    else:
        error = None

    if error:
        logger.error(error)
        click.secho(error, fg="red", err=True)
        sys.exit(1)

    # wshift = img.width//10
    # hshift = img.height//10
    # width += wshift*1
    # height += hshift*2

    if outline:
        if isinstance(outline, tuple):
            pass
        else:
            try:
                outline = tuple(bytes.fromhex(outline[1:]))
            except Exception as e:
                logger.error(e)
                click.secho("Invalid color hex", fg="red", err=True)
                sys.exit(1)

    print("Preparing image", end="")

    img = Image.open(image)
    width = img.width
    height = img.height
    wshift = width // 100
    hshift = height // 100

    n_width = width + 2 * wshift
    n_height = height + 2 * hshift

    if smart:
        # Sobel Edge
        ski_img = np.array(img)
        gray_img = color.rgb2gray(ski_img)
        pts = genSmartPoints(gray_img)
    else:
        pts = genPoints(points, n_width, n_height)

    print("\r", end="")
    print("Generated points", end="")

    final_img = genPoly(img.width,
                        img.height,
                        img,
                        pts,
                        wshift,
                        hshift,
                        outline,
                        pic=True)

    print("\r", end="")
    print("Making final tweaks", end="")

    if show:
        final_img.show()

    file_name = ""

    if name:
        file_name = f"{name}.png"
        final_img.save(file_name)
    else:
        file_name = f"wall-{int(time.time())}.png"
        final_img.save(file_name)

    print("\r", end="")
    print(f"Image is stored at {file_name}")

    if set_wall:
        msg, ret = setwallpaper(file_name)
        if ret:
            click.secho(msg, fg="green")
        else:
            logger.error(msg)
            click.secho(msg, fg="red")
Exemple #5
0
def shape(
    side,
    choice_of_shape,
    colors,
    show,
    outline,
    name,
    percent,
    use_nn,
    swirl,
    scale,
    set_wall,
):
    """Generates a HQ image of a beautiful shapes"""

    error = ""
    if side < 50:
        error = "Image too small. Minimum size 50"
    if percent is not None:
        if percent < 1 or percent > 10:
            error = f"Error {percent} : Percent range 1-10"

    if error:
        logger.error(error)
        click.secho(error, fg="red", err=True)
        sys.exit(1)

    side = side * scale  # increase size to anti alias

    if colors:
        if len(colors) < 2:
            error = "One color gradient not possible."
            logger.error(error)
            click.secho(error, fg="red", err=True)
            sys.exit(1)
        try:
            cs = [tuple(bytes.fromhex(c[1:])) for c in colors]
        except Exception as e:
            logger.error(e)
            click.secho("Invalid color hex", fg="red", err=True)
            sys.exit(1)
        img = nGradient(side, *cs)
    else:
        if use_nn:
            img = NbyNGradient(side)
        else:
            img = random_gradient(side)

    if swirl:
        img = swirl_image(img, swirl)

    if outline:
        if isinstance(outline, tuple):
            pass
        else:
            try:
                outline = tuple(bytes.fromhex(outline[1:]))
            except Exception as e:
                logger.error(e)
                click.secho("Invalid color hex", fg="red", err=True)
                sys.exit(1)

    print("Preparing image", end="")

    if choice_of_shape == "hex":
        percent = percent if percent else 5
        img = genHexagon(side, side, img, outline, per=(percent or 1))
    elif choice_of_shape == "sq":
        img = genSquares(side, side, img, outline, per=(percent or 1))
    elif choice_of_shape == "dia":
        img = genDiamond(side, side, img, outline, per=(percent or 1))
    elif choice_of_shape == "tri":
        img = genTriangle(side, side, img, outline, per=(percent or 1))
    elif choice_of_shape == "iso":
        img = genIsometric(side, side, img, outline, per=(percent or 1))
    else:
        error = """
        No shape given. To see list of shapes \"wallgen shape --help\"
        """
        logger.error(error)
        click.secho(error, fg="red", err=True)
        sys.exit(1)

    print("\r", end="")
    print("Making final tweaks", end="")

    img = img.resize((side // scale, side // scale), resample=Image.BICUBIC)

    if show:
        img.show()

    file_name = ""

    if name:
        file_name = f"{name}.png"
        img.save(file_name)
    else:
        file_name = f"wall-{int(time.time())}.png"
        img.save(file_name)

    print("\r", end="")
    print(f"Image is stored at {file_name}")
    if set_wall:
        msg, ret = setwallpaper(file_name)
        if ret:
            click.secho(msg, fg="green")
        else:
            logger.error(msg)
            click.secho(msg, fg="red")
Exemple #6
0
def poly(
    side,
    points,
    show,
    colors,
    outline,
    name,
    only_color,
    use_nn,
    swirl,
    scale,
    set_wall,
):
    """Generates a HQ low poly image using a gradient"""

    error = ""
    if side < 50:
        error = "Image too small. Minimum size 50"
    elif points < MIN_POINTS:
        error = f"Too less points. Minimum points {MIN_POINTS}"
    elif points > MAX_POINTS:
        error = f"Too many points. Maximum points {MAX_POINTS}"
    elif scale < 1:
        error = "Invalid scale value"

    if error:
        logger.error(error)
        click.secho(error, fg="red", err=True)
        sys.exit(1)

    side = side * scale  # increase size to anti alias

    shift = side // 10
    nside = side + shift * 2  # increase size to prevent underflow

    if colors:
        if len(colors) < 2:
            error = "One color gradient not possible."
            logger.error(error)
            click.secho(error, fg="red", err=True)
            sys.exit(1)
        try:
            cs = [tuple(bytes.fromhex(c[1:])) for c in colors]
        except Exception as e:
            logger.error(e)
            click.secho("Invalid color hex", fg="red", err=True)
            sys.exit(1)
        img = nGradient(nside, *cs)
    else:
        if use_nn:
            points = 1000 if points < 1000 else points
            img = NbyNGradient(nside)
        else:
            img = random_gradient(nside)

    if swirl:
        if only_color:
            img = img.resize((side // scale, side // scale),
                             resample=Image.BICUBIC)
        img = swirl_image(img, swirl)

    if not only_color:
        if outline:
            if isinstance(outline, tuple):
                pass
            else:
                try:
                    outline = tuple(bytes.fromhex(outline[1:]))
                except Exception as e:
                    logger.error(e)
                    click.secho("Invalid color hex", fg="red", err=True)
                    sys.exit(1)

        print("Preparing image", end="")
        pts = genPoints(points, nside, nside)

        print("\r", end="")
        print("Generated points", end="")
        img = genPoly(side, side, img, pts, shift, shift, outl=outline)

        print("\r", end="")
        print("Making final tweaks", end="")
        img = img.resize((side // scale, side // scale),
                         resample=Image.BICUBIC)

    if show:
        img.show()

    file_name = ""

    if name:
        file_name = f"{name}.png"
        img.save(file_name)
    else:
        file_name = f"wall-{int(time.time())}.png"
        img.save(file_name)

    print("\r", end="")
    print(f"Image is stored at {file_name}")

    if set_wall:
        msg, ret = setwallpaper(file_name)
        if ret:
            click.secho(msg, fg="green")
        else:
            logger.error(msg)
            click.secho(msg, fg="red")
Exemple #7
0
def shape(image, shape, show, outline, name, percent, set_wall):  # noqa: F811
    """ Generate a HQ image of a beautiful shapes """
    error = None
    if percent:
        if percent < 1 or percent > 10:
            error = "Percent range 1-10"

    if error:
        click.secho(error, fg='red', err=True)
        sys.exit(1)

    img = Image.open(image)

    width = img.width
    height = img.height

    if outline:
        try:
            outline = tuple(bytes.fromhex(outline[1:]))
        except Exception:
            click.secho("Invalid color hex", fg='red', err=True)
            sys.exit(1)

    print("Preparing image", end="")

    if shape == 'hex':
        percent = percent if percent else 5
        img = genHexagon(width, height, img, outline, pic=True, per=percent)
    elif shape == 'sq':
        img = genSquares(width, height, img, outline, pic=True, per=percent)
    elif shape == 'dia':
        img = genDiamond(width, height, img, outline, pic=True, per=percent)
    elif shape == 'tri':
        img = genTriangle(width, height, img, outline, pic=True, per=percent)
    elif shape == 'iso':
        img = genIsometric(width, height, img, outline, pic=True, per=percent)
    else:
        error = """
        No shape given. To see list of shapes \"wallgen pic shape --help\"
        """
        click.secho(error, fg='red', err=True)
        sys.exit(1)

    print("\r", end="")
    print("Making final tweaks", end="")

    if show:
        img.show()

    file_name = ""

    if name:
        file_name = "{}.png".format(name)
        img.save(file_name)
    else:
        file_name = "wall-{}.png".format(int(time.time()))
        img.save(file_name)

    print("\r", end="")
    print(f"Image is stored at {file_name}")
    if set_wall:
        msg, ret = setwallpaper(file_name)
        if ret:
            click.secho(msg, fg="green")
        else:
            click.secho(msg, fg="red")
Exemple #8
0
def poly(image, points, show, outline, name, smart, set_wall):  # noqa: F811
    """ Generates a HQ low poly image """

    if points < 3:
        error = "Too less points. Minimum points 3"
    elif points > 200000:
        error = "Too many points. Maximum points {}".format(200000)
    else:
        error = None

    if error:
        click.secho(error, fg='red', err=True)
        sys.exit(1)

    # wshift = img.width//10
    # hshift = img.height//10
    # width += wshift*1
    # height += hshift*2

    if outline:
        try:
            outline = tuple(bytes.fromhex(outline[1:]))
        except Exception:
            click.secho("Invalid color hex", fg='red', err=True)
            sys.exit(1)

    print("Preparing image", end="")

    img = Image.open(image)
    width = img.width
    height = img.height
    wshift = width // 100
    hshift = height // 100

    n_width = width + 2 * wshift
    n_height = height + 2 * hshift

    if smart:
        # Sobel Edge
        ski_img = np.array(img)
        gray_img = color.rgb2gray(ski_img)
        pts = genSmartPoints(gray_img)
    else:
        pts = genPoints(points, n_width, n_height)

    print("\r", end="")
    print("Generated points", end="")

    final_img = genPoly(img.width, img.height, img, pts,
                        wshift, hshift, outline, pic=True)

    print("\r", end="")
    print("Making final tweaks", end="")

    if show:
        final_img.show()

    file_name = ""

    if name:
        file_name = "{}.png".format(name)
        final_img.save(file_name)
    else:
        file_name = "wall-{}.png".format(int(time.time()))
        final_img.save(file_name)

    print("\r", end="")
    print(f"Image is stored at {file_name}")

    if set_wall:
        msg, ret = setwallpaper(file_name)
        if ret:
            click.secho(msg, fg="green")
        else:
            click.secho(msg, fg="red")