예제 #1
0
 /**
  * Use thumbnailer to pre-process a bitstream to generate a jpeg file.
  * Echoes an error message if a problem occurs (for the scheduler log).
  *
  * @param string $name name of the image to be pre-processed
  * @param string $fullPath absolute path to the image to be pre-processed
  * @return string
  * @throws Zend_Exception
  */
 public function preprocessByThumbnailer($name, $fullPath)
 {
     $tmpPath = UtilityComponent::getTempDirectory('thumbnailcreator');
     if (!file_exists($tmpPath)) {
         throw new Zend_Exception('Temporary thumbnail dir does not exist: ' . $tmpPath);
     }
     $copyDestination = $tmpPath . '/' . $name;
     copy($fullPath, $copyDestination);
     $jpegDestination = $tmpPath . '/' . $name . '.jpg';
     /** @var RandomComponent $randomComponent */
     $randomComponent = MidasLoader::loadComponent('Random');
     while (file_exists($jpegDestination)) {
         $jpegDestination = $tmpPath . '/' . $name . $randomComponent->generateInt() . '.jpg';
     }
     /** @var SettingModel $settingModel */
     $settingModel = MidasLoader::loadModel('Setting');
     $thumbnailerPath = $settingModel->getValueByName(MIDAS_THUMBNAILCREATOR_THUMBNAILER_KEY, $this->moduleName);
     $thumbnailerParams = array($copyDestination, $jpegDestination);
     $thumbnailerCmd = KWUtils::prepareExeccommand($thumbnailerPath, $thumbnailerParams);
     if (KWUtils::isExecutable($thumbnailerPath)) {
         KWUtils::exec($thumbnailerCmd);
     } else {
         unlink($copyDestination);
         throw new Zend_Exception('Thumbnailer does not exist or you do not have execute permission. Please check the configuration of thumbnailcreator module.');
     }
     if (!file_exists($jpegDestination)) {
         unlink($copyDestination);
         throw new Zend_Exception('Problem executing thumbnailer on your system');
     } else {
         unlink($copyDestination);
         return $jpegDestination;
     }
 }
예제 #2
0
 /** tests isExecutable function */
 public function testIsExecutable()
 {
     // this is tricky to test, as it is hard to make assumptions that hold
     // up across platforms
     $app = 'php';
     if (KWUtils::isWindows()) {
         $app .= '.exe';
     }
     // for now assume that 'php' will not be found when not looking in the path
     $this->assertFalse(KWUtils::isExecutable($app, false));
     // but 'php' will be found in the path
     $this->assertTrue(KWUtils::isExecutable($app, true));
 }