Esempio n. 1
0
def save_class():
    global filename
    global scaling
    global outfile
    global canvas
    global saveas
    outfile.set(saveas.get())
    p = Pyxelate(1, 1, color.get(), 1, 1, 0)
    image = io.imread(filename)
    height, width, _ = image.shape
    p.height = height // factor.get()
    p.width = width // factor.get()
    pyxelated = p.convert(image)
    if scaling > 1:
        pyxelated = transform.resize(pyxelated,
                                     ((height // factor.get()) * scaling,
                                      (width // factor.get()) * scaling),
                                     anti_aliasing=False,
                                     mode='edge',
                                     preserve_range=True,
                                     order=0)
    io.imsave(outfile.get(), pyxelated.astype(uint8))
    fimg3 = Image.open(outfile.get())
    fimg2 = fimg3.resize((300, 300), resample=0)
    fimg = ImageTk.PhotoImage(fimg2)
    canvas.create_image(20, 20, anchor=tk.NW, image=fimg)
    canvas.image = fimg
    canvas.pack(pady=3)
    fn = tk.Label(root, text="Saved to " + outfile.get())
    fn.pack(pady=3)
Esempio n. 2
0
            print(bar_rmv + "\tSkipping " + red("unsupported") + ":\t" +
                  dim(f_path) + f_name + '.' + red(f_ext))
            bar_redraw()
            continue

        print(bar_rmv + "\tProcessing image:\t" + dim(f_path) + f_name + '.' +
              f_ext)

        # Redraw status bar
        bar_redraw()

        # Get image dimensions
        height, width, _ = image.shape

        # Apply the dimensions to Pyxelate
        p.height = height // args.factor
        p.width = width // args.factor

        try:
            warnings.filterwarnings("error")
            pyxelated = p.convert(image)
        except KeyboardInterrupt:
            print(bar_rmv + "Cancelled with " + red("Ctrl+C"))
            bar_redraw(1)
            sys.exit(0)
        except IndexError as e:
            # When the file is not an image just move to the next file
            err_cnt += 1
            print_err(e)
            bar_redraw()
            continue
Esempio n. 3
0
    # Setup Pyxelate with placeholder dimensions 1x1
    p = Pyxelate(1,
                 1,
                 color=args.colors,
                 dither=args.dither,
                 alpha=args.alpha,
                 regenerate_palette=args.regenerate_palette,
                 random_state=args.random_state)

    # Prepare images to convert sequence
    if args.sequence:
        SEQUENCE = [io.imread(file) for file in IMAGE_FILES]
        SEQ_IMAGE = p.convert_sequence(SEQUENCE)
        HEIGHT, WIDTH, _ = io.imread(IMAGE_FILES[0]).shape
        p.height = HEIGHT // args.factor
        p.width = WIDTH // args.factor

    for i, image_file in enumerate(IMAGE_FILES):
        # Make a time stamp to calculate remaining
        if i or not args.sequence:
            # Calculate the time difference between iterations
            T_SPLIT += [t.time()]
            if T_SPLIT[1:]:
                if len(TIME_IMG) == AVG_LAST_VALS:
                    del TIME_IMG[0]
                diff = round(T_SPLIT[1] - T_SPLIT.pop(0), 1)
                TIME_IMG.append(diff)
        else:
            # Skip the first iteration to generate sequence palette
            print("\tPreparing to convert image sequence...")