Blame view

export/deepexport.php 1.69 KB
6c90d466   Andrea Petta   leafletjs
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
56
57
58
59
60
61
  <?php
  
  require '../Slim/Slim.php';
  
  /**
  * Class DeepExport
  */
  class DeepExport
  {
      private static $instance = null;
      private $app;
  
      public static function getInstance()
      {
          if(self::$instance == null)
          {
              $c = __CLASS__;
              self::$instance = new $c;
          }
  
          return self::$instance;
      }
  
      private function __construct()
      {
          \Slim\Slim::registerAutoloader();
          $this->app = new \Slim\Slim();
  
          $this->app->post('/export-datalet-as-img', function(){
              if(!empty($this->app->request()->params('svg_data'))) {
                  try {
                      $svg = $this->app->request()->params('svg_data');
  
                      $chart = new Imagick();
                      $chart->setFormat('SVG');
                      $chart->readImageBlob($svg);
                      $chart->setFormat("png24");
  
                      $logo = new Imagick();
                      $logo->readImage("pbrtpa.bmp");
  
                      $image = new Imagick();
                      $image->setFormat("png24");
                      $image->newImage($chart->getImageWidth() > $logo->getImageHeight() ? $chart->getImageWidth() : $logo->getImageWidth(),
                                       $chart->getImageHeight()+$logo->getImageHeight(),
                                       "white");
  
                      $image->compositeImage($chart, Imagick::COMPOSITE_COPY, 0, 0);
                      $image->compositeImage($logo, Imagick::COMPOSITE_COPY, 20, $chart->getImageHeight());
  
                      echo $image;
                  }catch (Exception $e){}
              }
          });
      }
      
      public function run(){
          //run the Slim app
          $this->app->run();
      }
  }