909 |
miho |
1 |
<?php |
|
|
2 |
function file_type($file){ |
|
|
3 |
$path_chunks = explode("/", $file); |
|
|
4 |
$thefile = $path_chunks[count($path_chunks) - 1]; |
|
|
5 |
$dotpos = strrpos($thefile, "."); |
|
|
6 |
return strtolower(substr($thefile, $dotpos + 1)); |
|
|
7 |
} |
|
|
8 |
/*PØI ZMÌNÌ NASTAVENÍ JE NUTNO VYMAZAT TEMP!!!*/ |
|
|
9 |
/*Absolutní cesta k obrázku ($HTTP_GET_VARS["pth"]=parametr pth v adrese stránky)*/ |
|
|
10 |
$path = "/var/www/Modules/".$HTTP_GET_VARS["pth"]."/"; |
|
|
11 |
/*Absolutní cesta k náhledu*/ |
|
|
12 |
$path1 = "/tmp/"; |
|
|
13 |
/*íøka náhledu*/ |
|
|
14 |
$width = "150"; |
|
|
15 |
/*Výka náhledu*/ |
|
|
16 |
$height = "150"; |
|
|
17 |
/*Pokud obrázek existuje dej do promìnné filename jeho cestu jinak tam dej cestu k obrázku nopicture2*/ |
|
|
18 |
if (file_exists($path.$HTTP_GET_VARS["fname"]."_Small.jpg")) { |
|
|
19 |
$filename = $HTTP_GET_VARS["fname"]."_Small.jpg"; |
|
|
20 |
} else { |
|
|
21 |
$filename = "nopicture2.jpg"; |
|
|
22 |
$path = "/var/www/Web/PIC/"; |
|
|
23 |
} |
|
|
24 |
$extension = file_type($filename); |
|
|
25 |
$remove_thumb = false; |
|
|
26 |
$img_size = array(); |
|
|
27 |
|
|
|
28 |
/*Pokud obrázek v tempu neexistuje potom...*/ |
|
|
29 |
if (!file_exists($path1.$filename)) { |
|
|
30 |
|
|
|
31 |
/*Naètení obrázku*/ |
|
|
32 |
if(in_array($extension, array('png', 'gif', 'jpg', 'jpeg'))){ |
|
|
33 |
if(!$img_size = getimagesize($path.$filename)){ |
|
|
34 |
$remove_thumb = true; |
|
|
35 |
} |
|
|
36 |
if($extension == 'gif'){ |
|
|
37 |
if(!$image = imagecreatefromgif($path.$filename)){ |
|
|
38 |
$remove_thumb = true; |
|
|
39 |
} |
|
|
40 |
}elseif($extension == 'png'){ |
|
|
41 |
if(!$image = imagecreatefrompng($path.$filename)){ |
|
|
42 |
$remove_thumb = true; |
|
|
43 |
} |
|
|
44 |
}elseif($extension == 'jpg' || $extension == 'jpeg'){ |
|
|
45 |
if(!$image = imagecreatefromjpeg($path.$filename)){ |
|
|
46 |
$remove_thumb = true; |
|
|
47 |
} |
|
|
48 |
} |
|
|
49 |
/*Zmìna velikosti a zaøízení neporuení pomìru stran*/ |
|
|
50 |
$img_height = $img_size['1']; |
|
|
51 |
$img_width = $img_size['0']; |
|
|
52 |
if($img_width > $img_height){ |
|
|
53 |
$thumb_width = $width; |
|
|
54 |
$thumb_height = ($img_height)*($height/$img_width); |
|
|
55 |
}elseif($img_width < $img_height) { |
|
|
56 |
$thumb_width = ($img_width)*($width/$img_height); |
|
|
57 |
$thumb_height = $height; |
|
|
58 |
}elseif($img_height == $img_width) { |
|
|
59 |
$thumb_width = $width; |
|
|
60 |
$thumb_height = $height; |
|
|
61 |
} |
|
|
62 |
if($remove_thumb == false){ |
|
|
63 |
$thumb = imagecreatetruecolor($thumb_width, $thumb_height); |
|
|
64 |
/*Pøeveï...*/ |
|
|
65 |
imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $img_size[0], $img_size[1] ); |
|
|
66 |
/*Pokud se má v rohu obrázku zobrazit text 'www.mlab.cz' potom odkomentovat následující 2 øádky a vymazat temp*/ |
|
|
67 |
// $black = ImageColorAllocate($thumb, 0, 0, 0); |
|
|
68 |
// if ($filename <> "nopicture2.jpg") {ImageString ($thumb, 3, $thumb_width-80, $thumb_height-15, "www.mlab.cz", $black);} |
|
|
69 |
/*Ulo obrázek!!!*/ |
|
|
70 |
imagejpeg($thumb, $path1.$filename); |
|
|
71 |
|
|
|
72 |
} |
|
|
73 |
}else{ |
|
|
74 |
$remove_thumb = true; |
|
|
75 |
} |
|
|
76 |
|
|
|
77 |
} |
|
|
78 |
|
|
|
79 |
/*Zobraz obrázek!!!*/ |
|
|
80 |
header("Content-type: image/jpeg"); |
|
|
81 |
readfile($path1.$filename); |
|
|
82 |
?> |