-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgiflib.class.php
executable file
·82 lines (65 loc) · 1.73 KB
/
giflib.class.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
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
*
*/
include "settings.class.php";
class GifLib
{
private $settings;
function __construct()
{
$this->settings = new Settings("gisicle.json");
}
function isGifCached($giflink) {
return file_exists("gifs/compressed_".$this->gifOrgName($giflink));
}
function compressGif($giflink) {
$gifname = $this->gifOrgName($giflink);
if($this->settings->get("colors")) {
$colors = $this->settings->get("colors");
} else {
$colors = 64;
}
if($this->settings->get("compression_rate")) {
$compression_rate = $this->settings->get("compression_rate");
} else {
$compression_rate = 350;
}
$output = shell_exec("screen -dmS compression-".substr($gifname, 0, -4)." scripts/launchCompression.sh ".$colors." ".$compression_rate." ".$gifname." ".$giflink." 2>&1");
}
function isCompressionRunning($giflink) {
$gifname = $this->gifOrgName($giflink);
$output = shell_exec("screen -ls | grep compression-".substr($gifname, 0, -4));
if($output != "") {
return true;
} else {
return false;
}
}
function gifOrgName($giflink) {
$gif_url_exploded = explode("/", $giflink);
return $gif_url_exploded[count($gif_url_exploded)-1];
}
function nbAndSize() {
$all_files = scandir("gifs/");
$nbAndSize = array();
$nbAndSize["nb"] = 0;
$nbAndSize["size"] = 0;
foreach ($all_files as $key => $file) {
if(substr($file, -3) == "gif" && $file != "compressed_blank.gif") {
$nbAndSize["nb"]++;
$nbAndSize["size"] += filesize("gifs/".$file);
}
}
return $nbAndSize;
}
function clearCache() {
$all_files = scandir("gifs/");
foreach ($all_files as $key => $file) {
if(substr($file, -3) == "gif" && $file != "compressed_blank.gif") {
unlink("gifs/".$file);
}
}
}
}
?>