Last active
April 17, 2016 11:56
-
-
Save y-a-v-a/d7a081d84caf1de098617e591e7601f1 to your computer and use it in GitHub Desktop.
First lesson - JPEG image manipulation with PHP
This file contains 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
<?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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 andcd
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.