]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - ImageTile.php
slide and thumbs mode by Thomas Harding
[SourceForge/phpwiki.git] / ImageTile.php
1 <?php
2
3 if (!file_exists($_REQUEST['url'])) {
4     header ("Content-type: text/html");
5     echo "<html><head></head><body>Not an image</body></html>";
6     exit();
7 }
8
9 list ($a, $b, $type, $attr) = @getimagesize ($_REQUEST['url']);
10
11 if ($type == 0) {
12
13     $type = basename ($_REQUEST['url']);
14     $type = preg_split ('/\./',$type);
15     $type = array_pop ($type);
16
17 }
18
19
20 switch ($type) {
21     case '2':
22         if (function_exists("imagecreatefromjpeg"))
23             $img = @imagecreatefromjpeg ($_REQUEST['url']);
24         else
25             show_plain ($_REQUEST['url']);
26         break;
27     case '3':
28         if (function_exists("imagecreatefrompng"))
29             $img = @imagecreatefrompng ($_REQUEST['url']);
30         else
31             show_plain ($_REQUEST['url']);
32         break;
33     case '1':
34         if (function_exists("imagecreatefromgif"))
35             $img = @imagecreatefromgif ($_REQUEST['url']);
36         else
37             show_plain ($_REQUEST['url']);
38         break;
39     case '15':
40         if (function_exists("imagecreatefromwbmp"))
41             $img = @imagecreatefromwbmp ($_REQUEST['url']);
42         else
43             show_plain ($_REQUEST['url']);
44         break;
45     case '16':
46         if (function_exists("imagecreatefromxbm"))
47             $img = @imagecreatefromxbm ($_REQUEST['url']);
48         else
49             show_plain ($_REQUEST['url']);
50         break;
51     case 'xpm':
52         if (function_exists("imagecreatefromxpm"))
53             $img = @imagecreatefromxpm ($_REQUEST['url']);
54         else
55             show_plain ($_REQUEST['url']);
56         break;
57     case 'gd':
58         if (function_exists("imagecreatefromgd"))
59             $img = @imagecreatefromgd ($_REQUEST['url']);
60         else
61             show_plain ($_REQUEST['url']);
62         break;
63     case 'gd2':
64         if (function_exists("imagecreatefromgd2"))
65             $img = @imagecreatefromgd2 ($_REQUEST['url']);
66         else
67             show_plain ($_REQUEST['url']);
68         break;
69     default:
70         //we are not stupid...
71         header ("Content-type: text/html");
72         echo "<html><head></head><body>Not an image</body></html>";
73         exit;
74         break;
75 }    
76
77 $width  = @imagesx($img);
78 $height = @imagesy($img);
79
80 $newwidth = $_REQUEST['width'];
81 if (empty($newidth)) $newidth = 50;
82     
83 $newheight = $_REQUEST['height'];
84 if (empty($newheight)) $newheight = round($newwidth * ($height / $width)) ;
85
86 $thumb = imagecreate($newwidth, $newheight);
87 $img = imagecopyresampled($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
88
89
90 header ("Content-type: image/png");
91 imagepng($thumb);
92
93 function show_plain () {
94     $mime = mime_content_type ($_REQUEST['url']);
95     header ("Content-type: $mime");
96     readfile($_REQUEST['url']);
97     exit ();
98 }
99
100 ?>