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