Created
June 19, 2015 10:57
-
-
Save y-a-v-a/6799c67f7b5cebfa4667 to your computer and use it in GitHub Desktop.
Simple glitch application that glitches images by manipulating the string data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env node | |
| var gd = require('node-gd'); | |
| var fs = require('fs'); | |
| var c; | |
| var img = fs.readFileSync('b.jpg', { encoding: 'binary' }); | |
| var imageBuffer = new Buffer(img, 'binary'); | |
| var newBuffer; | |
| var ch = ['aasd','gwer']; | |
| var replace; | |
| function rand() { | |
| return Math.floor(Math.random() * img.length); | |
| } | |
| for (var j = 0; j < 10; j++) { | |
| newBuffer = new Buffer(img.length); | |
| imageBuffer.copy(newBuffer); | |
| for (var i = 0; i < 100; i++) { | |
| c = rand(); | |
| replace = ch[Math.floor(Math.random() * ch.length)]; | |
| newBuffer.write(replace, c, 1); | |
| } | |
| try { | |
| var newImg = gd.createFromJpegPtr(newBuffer.toString('binary')); | |
| newImg.saveFile('test'+j+'.jpg'); | |
| // fs.writeFileSync('test.txt', b); | |
| } catch(e) { | |
| console.log('erroneous image'); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions:
0. Type in Terminal:
brew install gd. If this throws errors, type:ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"and then repeat step 0.cdinto that directory, likecd Projects/glitchnpm initand press enter many times.npm install --save node-gdand press enter.b.jpgor something, as long as you also change the name of it in line 6.node glitch.jsand hopefully you'll get glitched images!