-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.php
executable file
·64 lines (62 loc) · 1.69 KB
/
image.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
<?php
require("common.php");
function outputImage($img,$quality){
if(IMAGE_FORMAT=="jpeg"){
header('Content-Type: image/jpeg');
imagejpeg($img,NULL,$quality);
}
else if(IMAGE_FORMAT=="webp"){
header('Content-Type: image/webp');
imagewebp($img,NULL,$quality);
}
else
throw new Exception("Unsupported image format ".IMAGE_FORMAT);
imagedestroy($img);
}
$path=HOME.'/'.cleanPath(@$_GET["src"]);
if(@$_GET["reportSize"]){
echo json_encode(getSizeForFile($path));
die();
}
$size=@$_GET["size"];
if($size<2 && THUMB_EXIF_THUMBNAIL){
$data=exif_thumbnail($path);
if($data){
$img=@imagecreatefromstring($data);
}
}
if(@$img==NULL){
$img=@imagecreatefromjpeg($path);
}
if(@$img==NULL){
$img=getRaw($path,$size==0);
}
$width=imagesx($img);
$height=imagesy($img);
if($size==0){
// calculating the part of the image to use for thumbnail
if ($width > $height) {
$y = 0;
$x = ($width - $height) / 2;
$smallestSide = $height;
} else {
$x = 0;
$y = ($height - $width) / 2;
$smallestSide = $width;
}
$thumb = imagecreatetruecolor(THUMB_SIZE, THUMB_SIZE);
imagecopyresized($thumb, $img, 0, 0, $x, $y, THUMB_SIZE, THUMB_SIZE, $smallestSide, $smallestSide);
outputImage($thumb,THUMB_QUALITY);
}
$max_size=$size==1 ? THUMB_SIZE : FULL_SIZE;
$quality=$size==1 ? THUMB_QUALITY : FULL_SIZE_QUALITY;
if($max_size>0){
list($thumb_w,$thumb_h)=getSize($width,$height,$max_size);
$thumb = ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresized($thumb,$img,0,0,0,0,$thumb_w,$thumb_h,$width,$height);
outputImage($thumb,$quality);
}
else{
outputImage($img,$quality);
}
?>