-
Notifications
You must be signed in to change notification settings - Fork 16
/
thumb.php
55 lines (48 loc) · 1.79 KB
/
thumb.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
* Genera i thumbnail (diapositive) per le immagini allegate.
* Viene richiamato dal file {@link add.attach.php}
*
* @package VFront
* @author Mario Marcello Verona <[email protected]>
* @copyright 2007-2010 M.Marcello Verona
* @version 0.96 $Id: thumb.php 819 2010-11-21 17:07:24Z marciuz $
* @license http://www.gnu.org/licenses/gpl.html GNU Public License
*/
require("./inc/conn.php");
proteggi(1);
function printThumbnail($imgfile,$max_width=100,$max_height=100) {
list($org_width,$org_height,$orgtype) = getimagesize($imgfile);
$div_width = $org_width / $max_width;
$div_height = $org_height / $max_height;
if($div_width >= $div_height) {
$new_width = $max_width;
$new_height = round($org_height / $div_width);
}
else {
$new_height = $max_height;
$new_width = round($org_width / $div_height);
}
switch($orgtype) {
case 1: $im = imagecreatefromgif($imgfile); break;
case 2: $im = imagecreatefromjpeg($imgfile); break;
case 3: $im = imagecreatefrompng($imgfile); break;
}
if($im) {
$tn = imagecreatetruecolor($new_width,$new_height);
if($tn) {
imagecopyresized($tn,$im,0,0,0,0,$new_width,$new_height,$org_width,$org_height);
switch($orgtype) {
case 1: header("Content-Type: image/gif"); imagegif($tn); break;
case 2: header("Content-Type: image/jpeg"); imagejpeg($tn); break;
case 3: header("Content-Type: image/png"); imagepng($tn); break;
}
imagedestroy($tn);
}
}
}
$ID = (int) $_GET['id'];
$IMG=_PATH_ATTACHMENT."/$ID.dat";
if(is_file($IMG)){
printThumbnail($IMG,150,150);
}