Rev 767 | Rev 769 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | |
2 | |
3 | function file_type($file){ |
3 | function file_type($file){ |
4 | $path_chunks = explode("/", $file); |
4 | $path_chunks = explode("/", $file); |
5 | $thefile = $path_chunks[count($path_chunks) - 1]; |
5 | $thefile = $path_chunks[count($path_chunks) - 1]; |
6 | $dotpos = strrpos($thefile, "."); |
6 | $dotpos = strrpos($thefile, "."); |
7 | return strtolower(substr($thefile, $dotpos + 1)); |
7 | return strtolower(substr($thefile, $dotpos + 1)); |
8 | } |
8 | } |
9 | |
9 | |
10 | $path = "/var/www/Modules/".$HTTP_GET_VARS["pth"]."/"; |
10 | $path = "/var/www/Modules/".$HTTP_GET_VARS["pth"]."/"; |
- | 11 | |
|
- | 12 | if (file_exists($path.$HTTP_GET_VARS["fname"]."_Small.jpg")) { |
|
11 | $filename = $HTTP_GET_VARS["fname"]."_Small.jpg"; |
13 | $filename = $HTTP_GET_VARS["fname"]."_Small.jpg"; |
- | 14 | } else { |
|
- | 15 | $filename = "nopicture2.jpg"; |
|
- | 16 | $path = "/var/www/Web/PIC/"; |
|
- | 17 | } |
|
12 | // $thumbnail = thumbnail_name($filename); |
18 | // $thumbnail = thumbnail_name($filename); |
13 | $extension = file_type($filename); |
19 | $extension = file_type($filename); |
14 | $remove_thumb = false; |
20 | $remove_thumb = false; |
15 | $img_size = array(); |
21 | $img_size = array(); |
16 | $width = "150"; |
22 | $width = "150"; |
17 | $height = "150"; |
23 | $height = "150"; |
18 | |
24 | |
19 | if (!file_exists("/tmp/".$filename)) { |
25 | if (!file_exists("/tmp/".$filename)) { |
20 | |
26 | |
21 | if(in_array($extension, array('png', 'gif', 'jpg', 'jpeg'))){ |
27 | if(in_array($extension, array('png', 'gif', 'jpg', 'jpeg'))){ |
22 | if(!$img_size = getimagesize($path.$filename)){ |
28 | if(!$img_size = getimagesize($path.$filename)){ |
23 | $remove_thumb = true; |
29 | $remove_thumb = true; |
24 | } |
30 | } |
25 | if($extension == 'gif'){ |
31 | if($extension == 'gif'){ |
26 | if(!$image = imagecreatefromgif($path.$filename)){ |
32 | if(!$image = imagecreatefromgif($path.$filename)){ |
27 | $remove_thumb = true; |
33 | $remove_thumb = true; |
28 | } |
34 | } |
29 | }elseif($extension == 'png'){ |
35 | }elseif($extension == 'png'){ |
30 | if(!$image = imagecreatefrompng($path.$filename)){ |
36 | if(!$image = imagecreatefrompng($path.$filename)){ |
31 | $remove_thumb = true; |
37 | $remove_thumb = true; |
32 | } |
38 | } |
33 | }elseif($extension == 'jpg' || $extension == 'jpeg'){ |
39 | }elseif($extension == 'jpg' || $extension == 'jpeg'){ |
34 | if(!$image = imagecreatefromjpeg($path.$filename)){ |
40 | if(!$image = imagecreatefromjpeg($path.$filename)){ |
35 | $remove_thumb = true; |
41 | $remove_thumb = true; |
36 | } |
42 | } |
37 | } |
43 | } |
38 | $img_height = $img_size['1']; |
44 | $img_height = $img_size['1']; |
39 | $img_width = $img_size['0']; |
45 | $img_width = $img_size['0']; |
40 | if($img_width > $img_height){ |
46 | if($img_width > $img_height){ |
41 | $thumb_width = $width; |
47 | $thumb_width = $width; |
42 | $thumb_height = ($img_height)*($height/$img_width); |
48 | $thumb_height = ($img_height)*($height/$img_width); |
43 | }elseif($img_width < $img_height) { |
49 | }elseif($img_width < $img_height) { |
44 | $thumb_width = ($img_width)*($width/$img_height); |
50 | $thumb_width = ($img_width)*($width/$img_height); |
45 | $thumb_height = $height; |
51 | $thumb_height = $height; |
46 | }elseif($img_height == $img_width) { |
52 | }elseif($img_height == $img_width) { |
47 | $thumb_width = $width; |
53 | $thumb_width = $width; |
48 | $thumb_height = $height; |
54 | $thumb_height = $height; |
49 | } |
55 | } |
50 | if($remove_thumb == false){ |
56 | if($remove_thumb == false){ |
51 | $thumb = imagecreatetruecolor($thumb_width, $thumb_height); |
57 | $thumb = imagecreatetruecolor($thumb_width, $thumb_height); |
52 | imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $img_size[0], $img_size[1] ); |
58 | imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $img_size[0], $img_size[1] ); |
53 | imagejpeg($thumb, "/tmp/".$filename); |
59 | imagejpeg($thumb, "/tmp/".$filename); |
54 | |
60 | |
55 | } |
61 | } |
56 | }else{ |
62 | }else{ |
57 | $remove_thumb = true; |
63 | $remove_thumb = true; |
58 | } |
64 | } |
59 | |
65 | |
60 | } |
66 | } |
61 | |
67 | |
62 | |
68 | |
63 | header("Content-type: image/jpeg"); |
69 | header("Content-type: image/jpeg"); |
64 | readfile("/tmp/".$filename); |
70 | readfile("/tmp/".$filename); |
65 | ?> |
71 | ?> |