Skip to content

Instantly share code, notes, and snippets.

@y-a-v-a
Last active April 17, 2016 11:56
Show Gist options
  • Save y-a-v-a/d7a081d84caf1de098617e591e7601f1 to your computer and use it in GitHub Desktop.
Save y-a-v-a/d7a081d84caf1de098617e591e7601f1 to your computer and use it in GitHub Desktop.
First lesson - JPEG image manipulation with PHP
<?php
// loop 100 times
for ($j = 0; $j < 100; $j++) {
// open a file called some-file.jpg
// and store its data in a variable
$image = file_get_contents('./some-file.jpg');
// loop 10 times
for ($i = 0; $i < 10; $i++ ) {
// change some data in the data of the image
$image[($i * rand(800, 1000) ) + 1525] = 'ª¶§∞£tuy';
}
// save the data to a new file
// to make it unique, add a 'timestamp' in miliseconds
file_put_contents('./some-result-' . microtime(true) . '.jpg', $image);
}
// file end makes program end
@y-a-v-a
Copy link
Author

y-a-v-a commented Apr 17, 2016

To run this, save the above in a file in a specific directory (folder). Put an image in the same folder. Change the name of the file to some-file.jpg or change to code above to reflect the image's name.
Open the Terminal application and cd into the directory. For example:
cd Desktop/glitch
Run the program:
php php-jpeg-glitch.php
Open Finder and look what the result of your glitching is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment