Révision 2b7be83a
ID | 2b7be83a7d5ce229badd8f5d6dba626ed8db7b22 |
Parent | 5119cb9e |
Enfant | 00335597 |
moved panorama generation to class : PanoramaGenerator
Fichiers
- ajouté
- modifié
- copié
- renommé
- supprimé
Révisions
class/TilesGenerator.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
require_once(dirname(__FILE__).'/../constants.inc.php'); |
|
4 |
|
|
5 |
class TilesGeneratorException extends Exception {} |
|
6 |
class TilesGeneratorRightsException extends TilesGeneratorException {} |
|
7 |
class TilesGeneratorScriptException extends TilesGeneratorException {} |
|
8 |
|
|
9 |
class TilesGenerator { |
|
10 |
private $panorama; |
|
11 |
|
|
12 |
const SCRIPT_RELATIVE_PATH = 'to_tiles/gen_tiles.sh'; |
|
13 |
|
|
14 |
public function __construct($img_path, $panorama) { |
|
15 |
/** @param $img_path : path of the source image |
|
16 |
* @param $panorama : a site_point instance |
|
17 |
*/ |
|
18 |
$this->panorama = $panorama; |
|
19 |
$this->img_path = $img_path; |
|
20 |
} |
|
21 |
|
|
22 |
public function prepare() { |
|
23 |
$err = false; |
|
24 |
$pano_path = $this->panorama->tiles_path(); |
|
25 |
|
|
26 |
if (! is_dir(PANORAMA_PATH)) { |
|
27 |
if (! mkdir(PANORAMA_PATH)) { |
|
28 |
$err = "le répertoire \"PANORAMA_PATH\" n'est pas accessible et ne peut être créé"; |
|
29 |
} |
|
30 |
} else if (file_exists($pano_path)) { |
|
31 |
$err = sprintf("le nom de répertoire \"%s\" est déjà pris", |
|
32 |
$pano_path); |
|
33 |
} else { |
|
34 |
mkdir($pano_path); |
|
35 |
} |
|
36 |
if ($err) { |
|
37 |
throw (new TilesGeneratorRightsException($err)); |
|
38 |
} |
|
39 |
|
|
40 |
} |
|
41 |
|
|
42 |
public function mk_command() { |
|
43 |
/** Returns the command to execute |
|
44 |
*/ |
|
45 |
$c = sprintf('%s/%s -p "%s" "%s"', |
|
46 |
CELUTZ_PATH, $this::SCRIPT_RELATIVE_PATH, |
|
47 |
$this->panorama->tiles_prefix(), $this->img_path); |
|
48 |
return escapeshellcmd($c); |
|
49 |
} |
|
50 |
|
|
51 |
public function process() { |
|
52 |
$err = false; |
|
53 |
if ($fp = popen($this->mk_command(), 'r')) { |
|
54 |
while (!feof($fp)) { |
|
55 |
$results = fgets($fp, 4096); |
|
56 |
if (strlen($results) == 0) { |
|
57 |
// stop the browser timing out |
|
58 |
flush(); |
|
59 |
} else { |
|
60 |
$tok = strtok($results, "\n"); |
|
61 |
while ($tok !== false) { |
|
62 |
echo htmlspecialchars(sprintf("%s\n",$tok))."<br/>"; |
|
63 |
flush(); |
|
64 |
$tok = strtok("\n"); |
|
65 |
} |
|
66 |
} |
|
67 |
} |
|
68 |
if (pclose($fp) !== 0) { |
|
69 |
$err = "Opération en échec durant l'exécution du script"; |
|
70 |
} |
|
71 |
} else { |
|
72 |
$err = 'Opération en échec à l\'ouverture du script !'; |
|
73 |
} |
|
74 |
|
|
75 |
if ($err) { |
|
76 |
throw (new TilesGeneratorScriptException($err)); |
|
77 |
} |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
?> |
class/site_point.class.php | ||
---|---|---|
18 | 18 |
|
19 | 19 |
public function __construct($dir) { |
20 | 20 |
// si $dir n'est pas un répertoire il ne s'agit pas d'un panorama. |
21 |
if (!is_dir($dir)) { |
|
22 |
throw new PanoramaFormatException("$dir does not contain a panorama"); |
|
23 |
} |
|
21 |
// if (!is_dir($dir)) {
|
|
22 |
// throw new PanoramaFormatException("$dir does not contain a panorama");
|
|
23 |
// }
|
|
24 | 24 |
$this->base_dir = $dir; |
25 | 25 |
$this->prefix = basename($dir); |
26 | 26 |
} |
... | ... | |
29 | 29 |
return $this->base_dir.'/'.$this->prefix.'.params'; |
30 | 30 |
} |
31 | 31 |
|
32 |
public function tiles_path() { |
|
33 |
return $this->base_dir; |
|
34 |
} |
|
35 |
|
|
36 |
public function tiles_prefix() { |
|
37 |
return $this->base_dir.'/'.$this->get_prefix(); |
|
38 |
} |
|
39 |
|
|
32 | 40 |
private function parse_and_cache_params() { |
33 | 41 |
if (is_file($this->params_path())) { |
34 | 42 |
$params = parse_ini_file($this->params_path()); |
... | ... | |
82 | 90 |
|
83 | 91 |
public function get_magnifications() { |
84 | 92 |
$dir_fd = opendir($this->base_dir); |
93 |
$zoom_array = array(); |
|
85 | 94 |
while (false !== ($file = readdir($dir_fd))) { // extraction des paramètres de grossissement par le serveur |
86 | 95 |
//echo $file; |
87 | 96 |
if (preg_match('/(.*)_([0-9]+)_([0-9]+)_([0-9]+)\.jpg$/', $file, $reg)) { |
class/utils.class.php | ||
---|---|---|
42 | 42 |
} |
43 | 43 |
return $ret; |
44 | 44 |
} |
45 |
public static function strip_extension($filename) { |
|
46 |
/** Removes the extension from a file name |
|
47 |
* @return the stripped name |
|
48 |
*/ |
|
49 |
return preg_replace('/\.[^.]+$/', '', $filename); |
|
50 |
} |
|
45 | 51 |
} |
46 | 52 |
|
47 | 53 |
?> |
genererPano.php | ||
---|---|---|
6 | 6 |
<title>convertiseur image vers panorama</title> |
7 | 7 |
</head> |
8 | 8 |
|
9 |
<body> |
|
9 | 10 |
<?php |
10 | 11 |
require_once 'class/utils.class.php'; |
12 |
require_once 'class/site_point.class.php'; |
|
13 |
require_once 'class/TilesGenerator.php'; |
|
11 | 14 |
require_once 'constants.inc.php'; |
12 | 15 |
utils::init(); |
13 | 16 |
if (isset($_GET['name'])) { |
14 |
$pano_name = $_GET['name']; |
|
15 |
$pano_basename = preg_replace('/\.[^.]+$/', '', $pano_name); |
|
16 |
|
|
17 |
//Partie exécutante du script gen_tiles qui gènere les tuiles à partir d'une image. |
|
18 |
$pano_dest = PANORAMA_PATH.'/'.$pano_basename; |
|
19 |
if (! is_dir(PANORAMA_PATH)) { |
|
20 |
if (! mkdir(PANORAMA_PATH)) { |
|
21 |
echo "<p class=\"error\">le répertoire \"PANORAMA_PATH\" n'est pas accessible et ne peut être créé</p>\n"; |
|
22 |
} |
|
23 |
} else if (file_exists($pano_dest)) { |
|
24 |
echo "<p class=\"error\">le nom de répertoire \"$pano_dest\" est déjà pris</p>\n"; |
|
25 |
} else { |
|
26 |
mkdir($pano_dest); |
|
27 |
$escaped_command = escapeshellcmd('./to_tiles/gen_tiles.sh -p '.$pano_dest.'/'.$pano_basename.' ./upload/'.$pano_name); |
|
28 |
|
|
29 |
printf("<h2>Exécution de la commande :</h2>\n<p class=\"cmd\"><samp>%s</samp></p>\n<pre>", htmlspecialchars($escaped_command)); |
|
30 |
if ($fp = popen($escaped_command, 'r')) { |
|
31 |
while (!feof($fp)) { |
|
32 |
//set_time_limit (20); |
|
33 |
$results = fgets($fp, 4096); |
|
34 |
if (strlen($results) == 0) { |
|
35 |
// stop the browser timing out |
|
36 |
flush(); |
|
37 |
} else { |
|
38 |
$tok = strtok($results, "\n"); |
|
39 |
while ($tok !== false) { |
|
40 |
echo htmlspecialchars(sprintf("%s\n",$tok))."<br/>"; |
|
41 |
flush(); |
|
42 |
$tok = strtok("\n"); |
|
43 |
} |
|
44 |
} |
|
45 |
} |
|
46 |
print("</pre>\n"); |
|
47 |
if (pclose($fp) === 0) { |
|
48 |
print("<h4><span class=\"success\">Opération réussie</span></h4>\n"); |
|
49 |
printf("<p>Pour acceder directement au panorama <a href=\"panorama.php?dir=%s&panorama=%s\">cliquer ici</a></p>\n", |
|
50 |
PANORAMA_PATH, $pano_basename); |
|
51 |
} else { |
|
52 |
print("<h4><span class=\"error\">Opération en échec durant l'exécution du script !</span></h4>\n"); |
|
53 |
} |
|
54 |
} else { |
|
55 |
print("<h4><span class=\"error\">Opération en échec à l'ouverture du script !</span></h4>\n"); |
|
56 |
} |
|
17 |
$image_path = UPLOAD_PATH.'/'.$_GET['name']; |
|
18 |
// We init the panorama with the same name as image. |
|
19 |
$pano_name = utils::strip_extension($_GET['name']); |
|
20 |
$panorama = site_point::get($pano_name); |
|
21 |
|
|
22 |
$tiles_generator = new TilesGenerator($image_path, $panorama); |
|
23 |
|
|
24 |
try { |
|
25 |
$tiles_generator->prepare(); |
|
26 |
printf("<h2>Exécution de la commande :</h2>\n"); |
|
27 |
printf("<p class=\"cmd\"><samp>%s</samp></p>\n", |
|
28 |
$tiles_generator->mk_command()); |
|
29 |
|
|
30 |
echo "<pre>\n"; |
|
31 |
$tiles_generator->process(); |
|
32 |
print("</pre>\n"); |
|
33 |
|
|
34 |
|
|
35 |
print("<h4><span class=\"success\">Opération réussie</span></h4>\n"); |
|
36 |
printf("<p>Pour acceder directement au panorama <a href=\"%s\">cliquer ici</a></p>\n", |
|
37 |
$panorama->get_url()); |
|
38 |
print("<p>Pour acceder à la liste des panoramas <a href=\".\">cliquer ici</a></p>\n") ; |
|
39 |
|
|
40 |
|
|
41 |
} catch (TilesGeneratorRightsException $e) { |
|
42 |
printf("<p class=\"error\">%s</p>\n", $e->getMessage()); |
|
43 |
} catch (TilesGeneratorScriptException $e) { |
|
44 |
printf("<h4><span class=\"error\">%s</span></h4>\n", $e->getMessage()); |
|
45 |
print("</pre>\n"); |
|
57 | 46 |
} |
58 |
print("<p>Pour acceder à la liste des panoramas <a href=\".\">cliquer ici</a></p>\n") ; |
|
59 | 47 |
} |
60 | 48 |
?> |
49 |
</body> |
|
50 |
</html> |