-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeogram.php
executable file
·55 lines (46 loc) · 1.46 KB
/
keogram.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
<?php
// keogram
// (c) Cedric Raguenaud 2021
// Released under CC BY 4.0
$keogramfile = "keogram.jpg";
$sourcedir = "./temp/";
$font = './arial.ttf';
print("Listing files...\n");
$files = Array();
$d = dir($sourcedir);
while (false !== ($entry = $d->read())) {
if ($entry!="." && $entry!=".." && strpos($entry, ".jpg")!==false) {
$files[] = $entry;
}
}
$d->close();
sort($files);
if (count($files)>0) {
print("Loading files...\n");
$imagestats = getimagesize($sourcedir.$files[0]);
$height = $imagestats[1];
$keogram = imagecreate(count($files), $height+50);
//$keogram = imagecreate($imagestats[0], $height+50);
$white = imagecolorallocate($keogram, 255, 255, 255);
$grey = imagecolorallocate($keogram, 128, 128, 128);
$black = imagecolorallocate($keogram, 0, 0, 0);
imagefilledrectangle($keogram, 0, $height, $imagestats[0], 50, $white);
imagettftext($keogram, 20, 0, 0, $height+40, $grey, $font, "Keogram ".date("d-M-Y"));
$oldfiletime = 0;
$col = 0;
foreach($files as $file) {
$filetime = filemtime($sourcedir.$file);
$image = imagecreatefromjpeg($sourcedir.$file);
imagecopy($keogram, $image, $col, 0, $imagestats[0]/2, 0, 1, $imagestats[1]);
imagedestroy($image);
if (date("H", $filetime) != date("H", $oldfiletime)) {
imagettftext($keogram, 8, 0, $col, $height+15, $grey, $font, date("H", $filetime));
}
$oldfiletime = $filetime;
$col++;
}
print("Generating keogram...\n");
imagejpeg($keogram, $keogramfile);
imagedestroy($keogram);
}
?>