Beispiel #1
0
def gifMaker(inputPath, targetFormat):
    outputPath = os.path.splitext(inputPath)[0] + targetFormat

    reader = imageio.get_reader(inputPath)
    fps = reader.get_meta_data()['fps']

    writer = imageio.get_writer(outputPath, fps=fps)

    creatingGif = tk.Label(frame, text="Creating the gif")
    creatingGif.pack()

    for frames in reader:
        writer.append_data(frames)

    finishedGif = tk.Label(frame, text="Finished creating the gif")
    finishedGif.pack()

    writer.close()

    OptomizingGif = tk.Label(frame, text="Optomizing...")
    OptomizingGif.pack()

    gifsicle(outputPath)

    finishedOptomizingGif = tk.Label(frame, text="Finished optomizing")
    finishedOptomizingGif.pack()
Beispiel #2
0
 def save_images(self, save_uri):
     self.image_append()
     imageio.mimsave(save_uri, self.images, 'GIF', duration=self.DUR)
     print("GIF export complete!")
     optimize(save_uri)
     print("GIF optimize complete!")
     gifsicle(sources=[save_uri], optimize=False, options=['-O3'])
     print("GIF deep optimize complete!")
def createcovergif(maxfile, gifpath, basename, args):
    if args.cover != None:
        gifpath = args.cover
        print("Using Predetermined Path")
    else:
        print("Creating Cover GIF")
        numframes = 0
        video, audio = metadata(maxfile)
        duration = video.get("other_duration") / 1000
        width = video.get("other_width")
        reader = imageio.get_reader(maxfile)
        fps = reader.get_meta_data()['fps']
        writer = imageio.get_writer(gifpath, fps=fps / 2)

        startTime = float(duration)
        startTime = math.floor(startTime) * .75
        start = fps * startTime
        endTime = startTime + 5
        end = fps * endTime

        for i, frames in enumerate(reader):
            if i < start or i % 3 != 0:
                continue
            if i > end:
                break
            writer.append_data(frames)
        writer.close()

        factor = 1
        startloop = True
        tempgif = os.path.join(tempfile.gettempdir(),
                               f"{os.urandom(24).hex()}.gif")
        while startloop:
            scale = f"--scale={factor}"

            gifsicle(sources=[gifpath],
                     destination=tempgif,
                     optimize=True,
                     options=[scale])
            if os.stat(tempgif).st_size > 5000000:
                print(
                    f"File too big at {os.stat(tempgif).st_size} bytes\nReducing Size"
                )
                factor = factor * .7
                continue
            startloop = False
    try:
        upload = fapping_upload(1, tempgif)

    except:
        print("Try a different Approved host gif too large/Host Down")
        return
    return upload
Beispiel #4
0
def make_gif(path):
    ring_files = sorted(glob.glob('ring/*.png'), key=os.path.getmtime)
    print(f"ring files: {ring_files}")
    ring_images = list(map(lambda file: Image.open(file).crop((0, 108, 365, 605)), ring_files))

    files = sorted(glob.glob(f'capture/{path}/*.png'), key=os.path.getctime)
    images = list(map(lambda file: Image.open(file).crop((0, 108, 365, 605)), files))

    gif_file = f"output/{path}.gif"
    ring_images.extend(images)
    ring_images[0].save(gif_file, save_all=True, append_images=ring_images[1:], duration=200, loop=1, optimize=True)

    gifsicle(sources=gif_file, optimize=False, colors=256, options=["-O3"])

    print("save gif: done")
Beispiel #5
0
    def save(self, path="/home/admin/bot/go-cqhttp/data/images/"):

        # cv2.imshow("image", self.img)
        # cv2.waitKey(0)
        savepath = path + "_" + self.picname
        if self.gif:
            # imageio.mimsave(savepath, self.img)
            self.img[0].save(savepath,
                             save_all=True,
                             format='GIF',
                             loop=0,
                             optimize=False,
                             append_images=self.img[1:])
            gifsicle(sources=[savepath], options=['-O2', '--careful'])
        else:
            cv2.cv2.imwrite(savepath, self.img)
        return "_" + self.picname
Beispiel #6
0
    async def run(self):
        self.start("Starting compression...")

        output = self.rename_extension(self.output_file, "gif")
        if output.exists() and self.skip_existing:
            self.warn("Already exists, skipping...")
            return output

        gifsicle(
            str(self.input_file),
            optimize=True,
            colors=100,
            destination=str(self.output_file),
            options=["--loopcount=forever", "-O3", "--lossy=30"],
        )

        self.done()
        return output
Beispiel #7
0
    def scale_width_down(src, dest=None, size=None):
        """Reduce size of gif using gifsicle's scale method.

        Parameters
        -------------
        src:String,
            File or location of gif to be resized.
        dest:String,
            Path/filename for new gif.
        size:Integer,
            The amount of reduction to be applied.
        """
        reduction_size = '{}x_'.format(size)
        gifsicle(
            sources=[src],
            destination=dest,
            optimize=False,
            #colors=256,
            options=['--resize', reduction_size]
        )
Beispiel #8
0
def test_gifsicle_exceptions():
    with pytest.raises(ValueError):
        gifsicle("non_existent_gif.gif")
    png = "existent_png.png"
    gif = "existent_gif.gif"
    touch(png)
    touch(gif)
    with pytest.raises(ValueError):
        gifsicle(png)
    with pytest.raises(ValueError):
        gifsicle(gif, png)
    os.remove(png)
    os.remove(gif)