Projet

Général

Profil

Révision 2b7be83a

Ajouté par Jocelyn Delande il y a plus de 10 ans

moved panorama generation to class : PanoramaGenerator

Voir les différences:

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&amp;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>

Formats disponibles : Unified diff