├── examples ├── glados.gif ├── peacemaker.jpg ├── securitay.jpg ├── watch_doge.jpg ├── reaper_core.png ├── glados-glitched.gif ├── peacemaker-glitched.jpg ├── reaper_core-glitched.png ├── securitay-glitched.jpg └── watch_doge-glitched.jpg ├── LICENSE ├── README.md └── glitch.py /examples/glados.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sajattack/glitch/HEAD/examples/glados.gif -------------------------------------------------------------------------------- /examples/peacemaker.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sajattack/glitch/HEAD/examples/peacemaker.jpg -------------------------------------------------------------------------------- /examples/securitay.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sajattack/glitch/HEAD/examples/securitay.jpg -------------------------------------------------------------------------------- /examples/watch_doge.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sajattack/glitch/HEAD/examples/watch_doge.jpg -------------------------------------------------------------------------------- /examples/reaper_core.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sajattack/glitch/HEAD/examples/reaper_core.png -------------------------------------------------------------------------------- /examples/glados-glitched.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sajattack/glitch/HEAD/examples/glados-glitched.gif -------------------------------------------------------------------------------- /examples/peacemaker-glitched.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sajattack/glitch/HEAD/examples/peacemaker-glitched.jpg -------------------------------------------------------------------------------- /examples/reaper_core-glitched.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sajattack/glitch/HEAD/examples/reaper_core-glitched.png -------------------------------------------------------------------------------- /examples/securitay-glitched.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sajattack/glitch/HEAD/examples/securitay-glitched.jpg -------------------------------------------------------------------------------- /examples/watch_doge-glitched.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sajattack/glitch/HEAD/examples/watch_doge-glitched.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) <2015> 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # glitch.py 2 | Randomly changes binary file data in order to create glitch art. 3 | ## Usage 4 | ``` 5 | python glitch.py [percent] [outfile] 6 | 7 | infile: the file to take as input 8 | 9 | percent: the percentage of the file to corrupt, by default, 0.1% 10 | 11 | outfile: the file to output, by default -glitched. 12 | ``` 13 | 14 | Play around with different values for percent, 0.1 seems to work okay for most image formats, 0.01 worked okay for video. 15 | Also, try different filetypes and share your results! 16 | I noticed different image viewers sometimes perform differently with these glitched images. They either display the image differently or not at all. 17 | Windows Photo Viewer worked best for me. As a result, I usually screenshot the glitches from Windows Photo Viewer so they always display "correctly". 18 | 19 | ## Examples 20 | ![glados-original](/examples/glados.gif) 21 | 22 | ![glados-glitched](/examples/glados-glitched.gif) 23 | 24 | ![peacemaker-original](/examples/peacemaker.jpg) 25 | 26 | ![peacemaker-glitched](/examples/peacemaker-glitched.jpg) 27 | 28 | ![reaper_core-original](/examples/reaper_core.png) 29 | 30 | ![reaper_core-glitched](/examples/reaper_core-glitched.png) 31 | 32 | ![securitay-original](/examples/securitay.jpg) 33 | 34 | ![securitay-glitched](/examples/securitay-glitched.jpg) 35 | 36 | ![watch_doge-original](/examples/watch_doge.jpg) 37 | 38 | ![watch_doge-glitched](/examples/watch_doge-glitched.jpg) 39 | -------------------------------------------------------------------------------- /glitch.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | docstring = '''Randomly changes binary file data in order to create glitch art. 3 | Usage: glitch [percentage] [outfile] 4 | infile: the file to take as input 5 | percent: the percentage of the file to corrupt, by default, 0.1% 6 | outfile: the file to output, by default -glitched. 7 | ''' 8 | 9 | import sys, os, random 10 | 11 | headersize = {'jpg': 9, 'png': 8, 'bmp': 54, 'gif': 14, 'tiff': 8} 12 | 13 | def glitch(infile, percent, outfile): 14 | with open(infile, 'rb') as inf: 15 | with open(outfile, 'wb') as outf: 16 | 17 | #copy file header 18 | fileext = infile.split(".")[1] 19 | try: 20 | for byte in range(headersize[fileext]): 21 | inbyte = inf.read(1) 22 | outbyte = inbyte 23 | outf.write(outbyte) 24 | except KeyError: 25 | pass 26 | 27 | while True: 28 | inbyte = inf.read(1) 29 | if not inbyte: 30 | break 31 | if (random.random() < percent/100): 32 | outbyte = os.urandom(1) 33 | #outbyte = '\x00' 34 | else: 35 | outbyte = inbyte 36 | outf.write(outbyte) 37 | 38 | 39 | if __name__ == "__main__": 40 | argc = len(sys.argv) 41 | if (argc == 2): 42 | infile = sys.argv[1] 43 | percent = 0.1 44 | filename = infile.split(".")[0] 45 | fileext = infile.split(".")[1] 46 | outfile = filename + "-glitched" + "." + fileext 47 | glitch(infile, percent, outfile) 48 | elif (argc == 3): 49 | infile = sys.argv[1] 50 | percent = float(sys.argv[2]) 51 | filename = infile.split(".")[0] 52 | fileext = infile.split(".")[1] 53 | outfile = filename + "-glitched" + "." + fileext 54 | glitch(infile, percent, outfile) 55 | elif (argc == 4): 56 | infile = sys.argv[1] 57 | percent = float(sys.argv[2]) 58 | outfile = sys.argv[3] 59 | glitch(infile, percent, outfile) 60 | else: 61 | print(docstring) 62 | 63 | --------------------------------------------------------------------------------