Ejemplo n.º 1
0
 /**
  * @covers MediaAlchemyst\Alchemyst::turnInto
  * @covers MediaAlchemyst\Alchemyst::routeAction
  */
 public function testTurnIntoVideoVideo()
 {
     $dest = __DIR__ . '/../../files/output.webm';
     $this->object->turnInto(__DIR__ . '/../../files/Test.ogv', $dest, $this->specsVideo);
     $media = $this->getMediaVorus()->guess($dest);
     $this->assertEquals(MediaInterface::TYPE_VIDEO, $media->getType());
     unlink($dest);
 }
Ejemplo n.º 2
0
 public function write_databox_pic(Alchemyst $alchemyst, Filesystem $filesystem, databox $databox, SymfoFile $pathfile = null, $pic_type)
 {
     $filename = null;
     if (!is_null($pathfile)) {
         if (!in_array(mb_strtolower($pathfile->getMimeType()), ['image/jpeg', 'image/jpg', 'image/pjpeg', 'image/png', 'image/gif'])) {
             throw new \InvalidArgumentException('Invalid file format');
         }
     }
     if (!in_array($pic_type, [databox::PIC_PDF])) {
         throw new \InvalidArgumentException('unknown pic_type');
     }
     if ($pathfile) {
         $filename = $pathfile->getPathname();
         $imageSpec = new ImageSpecification();
         $imageSpec->setResizeMode(ImageSpecification::RESIZE_MODE_INBOUND_FIXEDRATIO);
         $imageSpec->setDimensions(120, 35);
         $tmp = tempnam(sys_get_temp_dir(), 'tmpdatabox') . '.jpg';
         try {
             $alchemyst->turninto($pathfile->getPathname(), $tmp, $imageSpec);
             $filename = $tmp;
         } catch (\MediaAlchemyst\Exception $e) {
         }
     }
     $file = $this->app['root.path'] . '/config/minilogos/' . $pic_type . '_' . $databox->get_sbas_id() . '.jpg';
     $custom_path = $this->app['root.path'] . '/www/custom/minilogos/' . $pic_type . '_' . $databox->get_sbas_id() . '.jpg';
     foreach ([$file, $custom_path] as $target) {
         if (is_file($target)) {
             $filesystem->remove($target);
         }
         if (is_null($filename)) {
             continue;
         }
         $filesystem->mkdir(dirname($target));
         $filesystem->copy($filename, $target);
         $filesystem->chmod($target, 0760);
     }
     $databox->delete_data_from_cache('printLogo');
     return $this;
 }
 /**
  * @expectedException MediaAlchemyst\Exception\RuntimeException
  */
 public function testTurnIntoVideoVideoWithFFProbe()
 {
     $driversContainer = new DriversContainer();
     $driversContainer['configuration'] = array('ffmpeg.ffprobe.binaries' => 'nofile');
     $object = new Alchemyst($driversContainer, $this->getFsManager());
     $dest = __DIR__ . '/../../files/output.webm';
     $object->turnInto(__DIR__ . '/../../files/Test.ogv', $dest, $this->specsVideo);
 }
Ejemplo n.º 4
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $spec = $this->getSpecification($input->getArgument('spec'));
     $file = $input->getArgument('file');
     if (!file_exists($file)) {
         throw new InvalidArgumentException(sprintf('file `%s` does not exists', $file));
     }
     $target = $input->getArgument('target');
     $force = $input->getOption('force');
     if (realpath($file) === realpath($target)) {
         throw new InvalidArgumentException('Source and target should be different');
     }
     if (file_exists($target) && !$force) {
         throw new InvalidArgumentException(sprintf('file `%s` already exists ; use --force to overwrite', $target));
     }
     if (method_exists($spec, 'setAudioCodec')) {
         if ($input->getOption('acodec')) {
             $spec->setAudioCodec($input->getOption('acodec'));
         }
     }
     if (method_exists($spec, 'setVideoCodec')) {
         if ($input->getOption('vcodec')) {
             $spec->setVideoCodec($input->getOption('vcodec'));
         }
     }
     if (method_exists($spec, 'setFrameRate')) {
         if ($input->getOption('framerate')) {
             $spec->setFrameRate($input->getOption('framerate'));
         }
     }
     if (method_exists($spec, 'setDimensions')) {
         if ($input->getOption('width') && $input->getOption('height')) {
             $spec->setDimensions($input->getOption('width'), $input->getOption('height'));
         } elseif (!$input->getOption('width') && $input->getOption('height') || $input->getOption('width') && !$input->getOption('height')) {
             throw new InvalidArgumentException('You should provide both dimensions or no dimensions');
         }
     }
     $drivers = new DriversContainer();
     $drivers['ffmpeg.threads'] = $input->getOption('threads') ?: 1;
     $fs = new Filesystem();
     $manager = new Manager(new TemporaryFilesystem($fs), $fs);
     $Alchemyst = new AlchemystTransmuter($drivers, $manager);
     $Alchemyst->turnInto($file, $target, $spec);
 }
 /**
  * @param File $file
  * @param $imageSpec
  * @return string
  * @throws \MediaAlchemyst\Exception\FileNotFoundException
  */
 protected function resizeMediaFile(File $file, $imageSpec)
 {
     $tmp = tempnam(sys_get_temp_dir(), 'tmpdatabox') . '.jpg';
     $this->alchemyst->turninto($file->getPathname(), $tmp, $imageSpec);
     return $tmp;
 }
Ejemplo n.º 6
0
 /**
  *
  * @param int        $angle
  * @param Alchemyst  $alchemyst
  * @param MediaVorus $mediavorus
  *
  * @return media_subdef
  */
 public function rotate($angle, Alchemyst $alchemyst, MediaVorus $mediavorus)
 {
     if (!$this->is_physically_present()) {
         throw new \Alchemy\Phrasea\Exception\RuntimeException('You can not rotate a substitution');
     }
     $specs = new \MediaAlchemyst\Specification\Image();
     $specs->setRotationAngle($angle);
     try {
         $alchemyst->turnInto($this->get_pathfile(), $this->get_pathfile(), $specs);
     } catch (\MediaAlchemyst\Exception\ExceptionInterface $e) {
         return $this;
     }
     $media = $mediavorus->guess($this->get_pathfile());
     $sql = "UPDATE subdef\n              SET height = :height , width = :width, updated_on = NOW()\n              WHERE record_id = :record_id AND name = :name";
     $params = [':width' => $media->getWidth(), ':height' => $media->getHeight(), ':record_id' => $this->get_record_id(), ':name' => $this->get_name()];
     $stmt = $this->record->get_databox()->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     $this->width = $media->getWidth();
     $this->height = $media->getHeight();
     $this->delete_data_from_cache();
     unset($media);
     return $this;
 }