-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimg.php
142 lines (122 loc) · 4.16 KB
/
img.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
ini_set('memory_limit', '2G');
include('include/main.inc.php');
$expires = 60*60*24*3;
header("Pragma: public");
header("Cache-Control: maxage=".$expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
$nocache = isset($_GET['nocache']);
$alpha = isset($_GET['alpha']);
$png = strstr($_SERVER['REQUEST_URI'],'png')!=false;
$gif = isset($_GET['gif']);
$noborder = isset($_GET['noborder']) ? 2 : false;
$type = $gif ? 'GIF' : ( $png ? 'PNG' : 'JPEG' );
$compression = $type == 'JPEG' && isset($_GET['c']) ? intval($_GET['c']) : 95;
$youtube = isset($_GET['youtube']);
$i = isset ($_GET['i']) ? $_GET['i']: false;
$tmp_youtube=false;
// Gestion d'images
if ($i) {
$source = Url::fromUrl($i);
$largeur_max = $_GET['x'];
$hauteur_max = $_GET['y'];
$cut = $_GET['cut'];
if(!file_exists($source))
exit;
if(strstr($_SERVER['REQUEST_URI'],'/img-')!==false) {
/* if (!is_dir($GLOBALS['chemin_site']."IMG/")){
@mkdir($GLOBALS['chemin_site']."IMG/",0777);
}*/
$uri = basename($_SERVER['REQUEST_URI']);
list($uri) = explode('?',$uri);
$cle = 'IMG/'.$uri;
} else {
/* if (!is_dir("CACHE/IMG/")){
@mkdir("CACHE",0777);
@mkdir("CACHE/IMG/",0777);
}*/
$cle = "CACHE/IMG/" . @filemtime($source) . md5(@filesize($source) . $source . $largeur_max . $hauteur_max . $cut . $gif. $alpha. $noborder);
}
$IF = new Image;
$cache = false;
if (!$nocache && file_exists($cle)) {
$cache = true;
}
if ($cache) {
$IF->loadImage($cle);
} else {
$size = getimagesize($source);
$largeur_src = $size[0];
$hauteur_src = $size[1];
// ini_set("memory_limit","16M");
//2ieme verification -> on verifie que le type du fichier est un jpg, jpeg ou gif
// $size[2] -> type de l'image : 1 = GIF , 2 = JPG, JPEG
if ($size[2] != 1 AND $size[2] != 2 AND $size[2] != 3) {
echo "Bad format"; exit;
}
$IF->loadImage($source);
if($noborder) {
$IF->crop($noborder,$noborder,$largeur_src-(2*$noborder),$hauteur_src-(2*$noborder));
}
$largeur_max = $largeur_max == 'max' ? intval($largeur_src * $hauteur_max / $hauteur_src) : $largeur_max;
$hauteur_max = $hauteur_max == 'max' ? intval($hauteur_src * $largeur_max / $largeur_src) : $hauteur_max;
// on verifie que l'image source ne soit pas plus petite que l'image de destination
if (($largeur_src > $largeur_max OR $hauteur_src > $hauteur_max)) {
if ($cut == 'true' || $cut == 'center' || $cut == 'top') {
// $largeur_max = $largeur_src <= $largeur_max ? $largeur_src : $largeur_max;
// $hauteur_max = $hauteur_src <= $hauteur_max ? $hauteur_src : $hauteur_max;
if ($largeur_src < $hauteur_src) {
$IF->resize($largeur_max, 0, "ratio");
} else {
$IF->resize(0, $hauteur_max, "ratio");
}
// $IF->resize($largeur_max, 0, "ratio");
$_s = $IF->getImageSize();
$largeur_max = $largeur_max > $_s['w'] ? $_s['w'] : $largeur_max;
$hauteur_max = $hauteur_max > $_s['h'] ? $_s['h'] : $hauteur_max;
if($cut == 'center') {
if($largeur_max < $hauteur_max) {
$dx = intval(($_s['w'] - $largeur_max) / 2);
$dy = 0;
} else {
$dx=0;
$dy = intval(($_s['h'] - $hauteur_max) / 2);
}
} else if($cut == 'top') {
$dx=0;
$dy=0;
} else {
$dx=0;
$dy=0;
}
$IF->crop($dx, $dy, $largeur_max, $hauteur_max);
} else {
// si la largeur est plus grande que la hauteur
if ($hauteur_src <= $largeur_src) {
$ratio = $largeur_max / $largeur_src;
} else {
$ratio = $hauteur_max / $hauteur_src;
}
$IF->resize(($ratio*100).'%','','force',true);
if(($ratio*100)>100)
$IF->blur();
// $IF->resize(round($largeur_src * $ratio), round($hauteur_src * $ratio));
}
$IF->rotation(180);
$IF->rotation(180);
}
if($alpha) {
// $IF->grayscale();
$IF->colorize('190', 0,0,0);
}
$_s = $IF->getImageSize();
$compression = $_s['w'] < 200 ? 75 : $compression;
$IF->output($type, $cle,NULL,$compression);
}
//header('Cache-Control: max-age=36000');
// $IF->output($type,NULL,NULL,$compression);
header('location: '.$GLOBALS['url_site'].$cle);
}
if($tmp_youtube) {
unlink($tmp_youtube);
}