Skip to content
Related Articles

Related Articles

Adding Glitches to Images using Python

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 08 Sep, 2021

One of the filters currently popular is to add random glitches to the images. These create a random effect that comes out to be a natural glitch. Usually, glitches are introduced by the corruption of frames of images or adding a layer over them. In this article, we will use the two different modules of Python to add glitches to the image.

Using GlitchArt Module

This Python library adds random glitch effects to Images. It does this by distorting or Corrupting JPEG frames of some random bytes of Images, to not harm the File. Internally it uses Pillow library to perform tasks. 


To install this module type the below command in the terminal.

pip3 install glitchart

After installation, the glitchart library is imported and jpeg() or png() is invoked depending upon the extension of the image to be glitched. Just run the script and a new glitched file will be created with the name <filename>_glitch in the same path.

Function Used:

png(): Add glitches to png images.


png(photo, seed=random_val, min_amount=0, max_amount=10, inplace=False):


  • photo :  The required .png format photo to add glitch to.
  • seed : Random number, if we wish to add similar amount of glitch to next photo, can have same seed value.
  • min_amount : Minimum amount of glitch required, defaults to 0.
  • max_amount : Maximum amount of glitch required, defaults to 10.
  • inplace : boolean field, if True, changes original photo, not creating new one.


Input Image:


import glitchart






Example 2: Controlling Glitch amount.



import glitchart
glitchart.png('gfg.png', max_amount=3)

Output : 

Using glitch-this Module 

Using this, we can perform the task of glitching images using command line by supplying image path and levels and certain image and file management parameters.


To install this module type the below command in the terminal

pip install glitch-this

Command Line Parameters Explanation

glitch_this [-h] [–version] [-c] [-s] [-g] [-ig] [-f] [-o Outfile_path] Image_Path Glitch_Level

Image_Path : The image path to perform glitch on.
Glitch_Level : Level of Glitch to be applied, from 0.1 to 10.0 [inclusive].
-h : Getting pull description
-o Outfile_path :Explicitly supply full/relative path to output file.
-g : Output image as gif.
-ig :  Include if input is gif.
-f : If output file has to be overwritten.
-c : If color effect has to be added.
-s. : If sideline effect has to be added.

Example: Controlling Glitch amount.

Example of Glitching using glitch-this

Output : 

Glitched Image Output

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!