-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglif.php
70 lines (50 loc) · 1.49 KB
/
glif.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
class Glif {
static public $iterations = 10;
static public $inputFile = 'input.jpg';
static public $outputDir = './frames';
static public $data;
static public $count = 1;
static public function corrupt($content) {
$image = $content;
foreach($image as $offset => $byte) {
if(rand(0, 10000) > 0 || $offset < 10) {
continue;
}
$byte = chr(rand());
$image[$offset] = $byte;
}
return $image;
}
static public function getInputArray() {
$input = file_get_contents(self::$inputFile);
$input = str_split($input);
return $input;
}
static public function getOutputFilePath() {
$path = self::$outputDir;
$path .= DIRECTORY_SEPARATOR;
$path .= uniqid();
$path .= '.jpg';
return $path;
}
static public function write($image) {
return file_put_contents(self::getOutputFilePath(), $image);
}
static public function generateFrame() {
$image = self::$data;
$image = self::corrupt($image);
echo self::$count, " ";
self::write($image);
self::$count++;
}
static public function run() {
if (! is_dir(self::$outputDir)) {
mkdir(self::$outputDir);
}
self::$data = self::getInputArray();
for($i=0; $i<self::$iterations; $i++) {
self::generateFrame();
}
}
}