Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
resizeimg.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Resize image (icons) by imagemagick converter
9  *
10  * @author Anakeen 2007
11  * @version $Id: resizeimg.php,v 1.10 2007/11/30 17:14:09 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage CORE
15  */
16 /**
17  */
18 include_once ("WHAT/Lib.Prefix.php");
19 include_once ("WHAT/Lib.Http.php");
20 include_once ("WHAT/Lib.Common.php");
21 
23 {
24  $source = $img;
25 
27 
28  $cmd = sprintf("convert -thumbnail %d %s %s", $size, escapeshellarg($source) , escapeshellarg($dest));
29  system($cmd);
30  if (file_exists($dest)) return $basedest;
31  return false;
32 }
33 
35 {
36  $source = $img;
37 
39 
40  $cmd = sprintf("/bin/cp %s %s", escapeshellarg($source) , escapeshellarg($dest));
41  system($cmd);
42  if (file_exists($dest)) return $basedest;
43  return false;
44 }
45 function getVaultPauth($vid)
46 {
47 
49  $rcore = pg_connect($dbaccess);
50  if ($rcore) {
51  $result = pg_query($rcore, "SELECT val from paramv where name='FREEDOM_DB' and type='G'");
52  if ($result) {
53  $row = pg_fetch_row($result);
54  $dbfree = current($row);
55 
56  if ($dbfree) {
57  $rfree = pg_connect($dbfree);
58  if ($rfree) {
59  $result = pg_query("select id_dir,name,public_access from vaultdiskstorage where id_file=$vid");
60  if ($result) {
61  $row = pg_fetch_row($result);
62  if ($row) {
63  $iddir = $row[0];
64  $name = $row[1];
65  $free = $row[2];
66 
67  if (!$free) return false;
68 
69  if (preg_match('/\.([^\.]*)$/', $name, $reg)) {
70  $ext = $reg[1];
71  }
72 
73  $result = pg_query("SELECT l_path,id_fs from vaultdiskdirstorage where id_dir = $iddir");
74  $row = pg_fetch_row($result);
75  $lpath = $row[0];
76  $idfs = $row[1];
77  $result = pg_query("SELECT r_path from vaultdiskfsstorage where id_fs = $idfs");
78  $row = pg_fetch_row($result);
79  $rpath = $row[0];
80 
81  $localimg = "$rpath/$lpath/$vid.$ext";
82  if (file_exists($localimg)) return $localimg;
83  }
84  }
85  }
86  }
87  }
88  }
89  return false;
90 }
91 
92 function getVaultCacheImage($vid, $size)
93 {
94  $basedest = "/img-cache/$size-vid$vid.png";
95  return $basedest;
96 }
97 
98 $size = $_GET["size"];
99 $img = $_GET["img"];
100 if (!$img) {
101  $vid = $_GET["vid"];
102  if ($vid > 0) $img = "vaultid=$vid";
103 }
104 
105 $dir = dirname($_SERVER["SCRIPT_NAME"]);
107 if (preg_match("/vaultid=([0-9]+)/", $img, $vids)) {
108  // vault file
109  $vid = $vids[1];
112  if (file_exists($dest)) {
113  $location = $ldir . "/" . $basedest;
114  } else {
115  $localimage = getVaultPauth(intval($vid));
116  if ($localimage) {
117  $tsize = getimagesize($localimage);
118 
119  $width = intval($tsize[0]);
120  if ($width > $size) {
121  $newimg = rezizelocalimage($localimage, $size, $basedest);
122  } else {
123  $newimg = copylocalimage($localimage, $size, $basedest);
124  }
125  if ($newimg) $location = "$ldir/$newimg";
126  }
127  }
128 } else {
129  // local file
130  $turl = (parse_url($img));
131  $path = $turl["path"];
132 
133  if (strstr($path, $dir) == $path) {
134  $localimage = substr($path, strlen($dir));
135  } else {
136  $localimage = $img;
137  }
138  $basedest = "/img-cache/$size-" . basename(str_replace("/", "_", $localimage)) . ".png";
140 
141  if (file_exists($dest) && filemtime($dest) >= filemtime(DEFAULT_PUBDIR . "/$localimage")) {
142  $location = "$ldir/$basedest";
143  } else {
144  $newimg = rezizelocalimage(DEFAULT_PUBDIR . "/$localimage", $size, $basedest);
145  if ($newimg) $location = "$ldir/$newimg";
146  }
147 }
148 //print("<hr>Location: $location");
149 if ($location) $location = "/" . ltrim($location, "/");
151 
152 Http_DownloadFile($location, basename($location) , "image/png", true, true);
153 //Header("Location: $location");
154 
155 ?>
← centre documentaire © anakeen - published under CC License - Dynacase