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