Gif Maker – Python App

#Create a folder called gif_maker

#Create a new file in Visual Studio Code under this project called ‘gifmaker’

#Put your video clip in this folder

#Open a new terminal and install the following using cmd in the terminal

pip install imageio imageio-ffmpeg

# You won’t need the terminal again for now

# Add the following imports to your new gifmaker page

import imageio

import os

# I made it interactive so the user has to input the name and extension of the file (as saved in the folder when prompted. exhibit a

# If you want the user to have to edit the literal code then insert as exhibit b shows

# After you have chosen to copy exhibit a or exhibit b then follow the rest of the code as shown below in the image. I have written it below for you to be able to copy and paste too.

import imageio
import os

print("Enter Clip name and extension e.g; bball.mp4")
clip_name = input()

clip = os.path.abspath(clip_name)


def gifmaker(inputPath, targetFormat):
    outputPath = os.path.splitext(inputPath)[0] + targetFormat

    print(f'converting {inputPath} \n to {outputPath}')

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

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

    for frames in reader:
        writer.append_data(frames)
        print(f'Frame{frames}')
    print('Done!')
    writer.close()


gifmaker(clip, '.gif')

# Once all code is completed you can save and run the application in a terminal

python [insert python app name].py

# The app will now load. If you went for exhibit a (interactive). The user will be prompted to enter the file name

#Enter exactly the file name with the extension as it appears in the folder

#Press enter and watch your gif get created!

generating…

#When it is completed you will see your message “Done!”. Got to your folder and see your gif!

# I Compress these files using the website below

#Compress your gif file size here

file size is currently: 29.56MiB – I put the compression level to 135…
image is now 5.84MiB !!

Please leave a comment below letting me know how you found this and any ways in which I can make following along easier! Also share and give it a Like!

Thanks x

Any Thoughts?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s