Skip to content

Documentation: The glitch this library

Chase edited this page Feb 25, 2020 · 8 revisions

Welcome to the glitch-this library docs! Here you will find all the information you need to get glitching, in any python project you like!

If you don't have the library already, get it on pypi

A full example of how you can use the class is in test_script.py

First you need to import the required class - ImageGlitcher

from glitch_this import ImageGlitcher

Now you can instantiate the class

glitcher = ImageGlitcher()

Now all you have to do is call the methods mentioned here and pass in the necessary parameters!

Method- glitch_image(self, src_img, glitch_amount, color_offset=False, scan_lines=False, gif=False, frames=23)

Returns an Image object if gif is set to False

Returns a list of PngImageFile objects if gif is set to True

Required Params

  • src_img: Either Full/Relative path to the Image you'd like to glitch (OR) A PIL Image object
  • glitch_amount: An integer between 1 to 10 (including both 1 and 10), signifying how glitched the output image should be

Optional Params

  • color_offset: Specify whether to use color offset effect (recommended True)

    Defaults to False

  • scan_lines: Specify whether to use scan lines effect, for an old school CRT TV look!

    Defaults to False

  • gif: Specify whether the returned object should be ready to be saved as a GIF

    If True, the function will return a list of PngImageFile objects, ready to be made into a GIF!

    Defaults to False

  • frames: Specify how many glitched images to store in the list of PngImageFile

    Defaults to 23

Code examples!

All these examples have color_offset turned on

For example if you wanted to get a glitched image, of glitch level 2 (with color_offset), for an image file in the same folder named test.png, you'd do-

from glitch_this import ImageGlitcher
glitch_img = glitcher.glitch_image('test.png', 2, color_offset=True)

You could also pass in the Image object itself;

from PIL import Image
from glitch_this import ImageGlitcher
img = Image.open('test.png')
glitch_img = glitcher.glitch_image(img, 2, color_offset=True)

You can now save it using

glitch_img.save('glitched_test.png')

Or you can do anything at all with the returned Image object!

How about GIFs? Let's do one of those!

from glitch_this import ImageGlitcher
glitch_img = glitcher.glitch_image('test.png', 2, color_offset=True, gif=True)

Again, you could also pass in the Image object itself;

from PIL import Image
from glitch_this import ImageGlitcher
img = Image.open('test.png')
glitch_img = glitcher.glitch_image(img, 2, color_offset=True, gif=True)

Same thing right? Well how do we save it? Like this!

DURATION = 200      # Set this to however many centiseconds each frame should be visible for
LOOP = 0            # Set this to how many times the gif should loop
                    # LOOP = 0 means infinite loop
glitch_img[0].save('glitched_test.gif',
                   format='GIF',
                   append_images=glitch_img[1:],
                   save_all=True,
                   duration=DURATION,
                   loop=LOOP)

Method- glitch_gif(self, src_gif, glitch_amount, color_offset=False, scan_lines=False)

Returns the following:

  • List of PngImage objects,
  • Average duration (in centiseconds) of each frame in the original GIF,
  • Number of frames in the original GIF

Required Params

  • src_img: Either Full/Relative path to the GIF Image you'd like to glitch (OR) A PIL Image object (must be GIF)
  • glitch_amount: An integer between 1 to 10 (including both 1 and 10), signifying how glitched the output image should be

Optional Params

  • color_offset: Specify whether to use color offset effect (recommended True)

    Defaults to False

  • scan_lines: Specify whether to use scan lines effect, for an old school CRT TV look!

    Defaults to False

Code examples!

All these examples have color_offset turned on

For example if you wanted to get a glitched gif, of glitch level 2 (with color_offset), for a GIF file in the same folder named test.gif, you'd do-

from glitch_this import ImageGlitcher
glitch_img, src_gif_duration, src_gif_frames = glitcher.glitch_gif('test.gif', 2, color_offset=True)

You could also pass in the Image object itself;

from PIL import Image
from glitch_this import ImageGlitcher
img = Image.open('test.gif')
glitch_img, src_gif_duration, src_gif_frames = glitcher.glitch_gif(img, 2, color_offset=True)

You can now save it using

DURATION = 200      # Set this to however many centiseconds each frame should be visible for
LOOP = 0            # Set this to how many times the gif should loop
                    # LOOP = 0 means infinite loop

# You could also use the `src_gif_duration` returned by `glitch_gif` 
# To keep the GIF exactly the same durationwise

glitch_img[0].save('glitched_test.gif',
                   format='GIF',
                   append_images=glitch_img[1:],
                   save_all=True,
                   duration=DURATION,
                   loop=LOOP)

Or you can do anything at all with the returned Image object!

That's it! Get glitchin'!

Clone this wiki locally