Exemplo n.º 1
0
 /**
  * Re-generate a screenshot using the metadata stored in the
  * `screenshots` database table.
  *
  * @return
  */
 public function reTakeScreenshot($screenshotId)
 {
     include_once HV_ROOT_DIR . '/../src/Database/ImgIndex.php';
     include_once HV_ROOT_DIR . '/../src/Image/Composite/HelioviewerScreenshot.php';
     include_once HV_ROOT_DIR . '/../src/Helper/HelioviewerLayers.php';
     include_once HV_ROOT_DIR . '/../src/Helper/HelioviewerEvents.php';
     include_once HV_ROOT_DIR . '/../src/Helper/RegionOfInterest.php';
     // Default options
     $defaults = array('force' => false, 'display' => false);
     $options = array_replace($defaults, $this->_params);
     $screenshotId = intval($screenshotId);
     if ($screenshotId <= 0) {
         throw new Exception('Value of screenshot "id" parameter is invalid.', 25);
     }
     $imgIndex = new Database_ImgIndex();
     $metaData = $imgIndex->getScreenshotMetadata($screenshotId);
     $options['timestamp'] = $metaData['timestamp'];
     $options['observationDate'] = $metaData['observationDate'];
     $roiArr = explode(',', str_replace(array('POLYGON((', '))'), '', $metaData['roi']));
     $roi = array();
     foreach ($roiArr as $index => $coordStr) {
         $coordArr = explode(' ', $coordStr);
         if ($index === 0) {
             $x1 = $coordArr[0];
             $y1 = $coordArr[1];
             $x2 = $coordArr[0];
             $y2 = $coordArr[1];
         } else {
             if ($coordArr[0] <= $x1 && $coordArr[1] <= $y1) {
                 $x1 = $coordArr[0];
                 $y1 = $coordArr[1];
             } else {
                 if ($coordArr[0] >= $x2 && $coordArr[1] >= $y2) {
                     $x2 = $coordArr[0];
                     $y2 = $coordArr[1];
                 }
             }
         }
     }
     $roi = new Helper_RegionOfInterest($x1, $y1, $x2, $y2, $metaData['imageScale']);
     // Data Layers
     $layers = new Helper_HelioviewerLayers($metaData['dataSourceString']);
     // Limit screenshot to five layers
     if ($layers->length() < 1 || $layers->length() > 5) {
         throw new Exception('Invalid layer choices! You must specify 1-5 comma-separated ' . 'layer names.', 22);
     }
     // Event Layers
     $events = new Helper_HelioviewerEvents($metaData['eventSourceString']);
     // Create the screenshot
     $screenshot = new Image_Composite_HelioviewerScreenshot($layers, $events, (bool) $metaData['eventsLabels'], (bool) $metaData['scale'], $metaData['scaleType'], $metaData['scaleX'], $metaData['scaleY'], $metaData['observationDate'], $roi, $options);
 }