forked from MediaFrontPage/mediafrontpage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sickbeardposter.php
executable file
·94 lines (82 loc) · 2.12 KB
/
sickbeardposter.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
<?php
require_once "config.php";
if(!empty($_GET["show"])) {
$cachefile = dirname(__FILE__)."/sbpcache/".$_GET["show"].".tbn";
if(file_exists($cachefile)) {
$image_out = file_get_contents($cachefile);
header('Content-type: image/png');
echo $image_out;
} else {
// Display image and write to cache.
// For the cache to work you need to create a director in the same location as this file:
// $ mkdir sbpcache
// $ chmod 777 sbpcache
resizedimage($sickbeardurl."/showPoster/?show=".$_GET["show"], $cachefile);
}
}
function sickbeardposter($imagesrc){
global $sickbeardurl;
$pos = strpos($imagesrc, "/showPoster/?");
if($pos > 0) {
resizedimage($sickbeardurl.substr($imagesrc, $pos + 1));
}
}
function resizedimage($imageurl, $cache = "") {
// actual script begins here
$size = getimagesize($imageurl);
switch($size["mime"]){
case "image/jpeg":
$image = imagecreatefromjpeg($imageurl); //jpeg file
break;
case "image/gif":
$image = imagecreatefromgif($imageurl); //gif file
break;
case "image/png":
$image = imagecreatefrompng($imageurl); //png file
break;
default:
$image = false;
echo "<pre>".print_r($size, 1)."</pre>";
return false;
break;
}
$width = $size[0];
$height = $size[1];
// Get new dimensions
$percent = 100 / $width;
$new_width = $width * $percent;
$new_height = $height * $percent;
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
ob_start();
switch($size["mime"]){
case "image/jpeg":
imagejpeg($image_p, null, 100); //jpeg file
break;
case "image/gif":
imagegif($image_p); //gif file
break;
case "image/png":
imagepng($image_p, null, 100); //png file
break;
default:
}
// Free up memory
imagedestroy($image);
imagedestroy($image_p);
$image_out = ob_get_contents();
ob_end_clean();
// Output
header('Content-type: '.$size["mime"]);
echo $image_out;
if(strlen($cache) > 0) {
// Save to cache.
if ($handle = fopen($cache, 'w')) {
if(fwrite($handle, $image_out)) {
fclose($handle);
}
}
}
}
?>