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