// title: JPEG / JPG Glitcher // author: rukano // description: // This code, based on uiae's blogpost takes a JPG file and replaces some bytes on it to mess up the codec. The result, some funny glitches // code: // code found @ "http://uiae.de/?p=110" // based on: http://www.hellocatfood.com/create-jpgs-in-pure-data/ // test with jpeg data here: http://www.ffd8.org/header_remix/?showall=yup ( // make 10 glitched versions of a JPEG 10.do{ |i| // change here the path of the original image and the path to the glithced images var inpath = "/Users/rukano/Desktop/monalisa.jpg"; var outpath = "/Users/rukano/Desktop/monalisa-glitch-%.jpg".format(i); var outfile; var file = File.open(inpath, "rb"); var data = file.length.collect{ file.getInt8 }; // how many bytes to replace 100.do{ var pos = rrand(200, data.size - 10); data[pos] = 256.rand; // data[pos] = (data[pos] + 100.rand2).max(0).min(255); }; // write out the file outfile = File.new(outpath, "wb"); outfile.write(data.as(Int8Array)); outfile.close; "---> wrote %".format(outpath).postln; }; )