/** * @covers SwfTools\Binary\Swfextract::extract */ public function testExtract() { $file = __DIR__ . '/../../../files/flashfile.swf'; $flash = new \SwfTools\Processor\FlashFile(DriverContainer::create()); $embeddeds = $flash->listEmbeddedObjects($file); $embedded = null; foreach ($embeddeds as $e) { if ($e->getType() === \SwfTools\EmbeddedObject::TYPE_JPEG) { $embedded = $e; break; } } $dest_file = __DIR__ . '/../../../files/tmp.jpg'; $this->object->extract($file, $embedded, $dest_file); $sizes = getimagesize($dest_file); $this->assertTrue(file_exists($dest_file)); unlink($dest_file); try { $this->object->extract($file, $embedded, ''); $this->fail('Should fail on invalid destination'); } catch (\SwfTools\Exception\InvalidArgumentException $exception) { } $this->assertEquals(1440, $sizes[0]); $this->assertEquals(420, $sizes[1]); $fakeFile = __DIR__ . '/../../../files/nofile'; try { $this->object->extract($fakeFile, $embedded, $dest_file); $this->fail('Swfrender should file on an unexistent file'); } catch (\SwfTools\Exception\RuntimeException $exception) { } }
public function register(Application $app) { $app['swftools.default.configuration'] = array('pdf2swf.binaries' => 'pdf2swf', 'swfrender.binaries' => 'swfrender', 'swfextract.binaries' => 'swfextract', 'timeout' => 60); $app['swftools.configuration'] = array(); $app['swftools.logger'] = null; $app['swftools.driver-container'] = $app->share(function (Application $app) { $app['swftools.configuration'] = array_replace($app['swftools.default.configuration'], $app['swftools.configuration']); return DriverContainer::create($app['swftools.configuration'], $app['swftools.logger']); }); $app['swftools.pdf-file'] = $app->share(function (Application $app) { return new PDFFile($app['swftools.driver-container']); }); $app['swftools.flash-file'] = $app->share(function (Application $app) { return new FlashFile($app['swftools.driver-container']); }); }
public function __construct() { $this['logger.name'] = 'Media-Alchemyst drivers logger'; $this['logger.level'] = function (Pimple $container) { return Logger::DEBUG; }; $this['logger.handler'] = $this->share(function (Pimple $container) { return new NullHandler($container['logger.level']); }); $bridge = class_exists('Symfony\\Bridge\\Monolog\\Logger'); $this['logger.class'] = $bridge ? 'Symfony\\Bridge\\Monolog\\Logger' : 'Monolog\\Logger'; $this['logger'] = $this->share(function (Pimple $container) { $logger = new $container['logger.class']($container['logger.name']); $logger->pushHandler($container['logger.handler']); return $logger; }); $this['default.configuration'] = array('ffmpeg.threads' => 4, 'ffmpeg.ffmpeg.timeout' => 3600, 'ffmpeg.ffprobe.timeout' => 60, 'ffmpeg.ffmpeg.binaries' => null, 'ffmpeg.ffprobe.binaries' => null, 'imagine.driver' => null, 'gs.timeout' => 60, 'gs.binaries' => null, 'mp4box.timeout' => 60, 'mp4box.binaries' => null, 'swftools.timeout' => 60, 'swftools.pdf2swf.binaries' => null, 'swftools.swfrender.binaries' => null, 'swftools.swfextract.binaries' => null, 'unoconv.binaries' => null, 'unoconv.timeout' => 60); $this['configuration'] = array(); $this['configuration.merged'] = $this->share(function (Pimple $container) { return array_replace($container['default.configuration'], $container['configuration']); }); $this['ffmpeg.ffmpeg'] = $this->share(function (Pimple $container) { try { return FFMpeg::create(array_filter(array('ffmpeg.threads' => $container['configuration.merged']['ffmpeg.threads'], 'timeout' => $container['configuration.merged']['ffmpeg.ffmpeg.timeout'], 'ffmpeg.binaries' => $container['configuration.merged']['ffmpeg.ffmpeg.binaries'])), $container['logger'], $container['ffmpeg.ffprobe']); } catch (FFMpegExecutableNotFound $e) { throw new RuntimeException('Unable to create FFMpeg driver', $e->getCode(), $e); } }); $this['ffmpeg.ffprobe.cache'] = $this->share(function (Pimple $container) { return new ArrayCache(); }); $this['ffmpeg.ffprobe'] = $this->share(function (Pimple $container) { try { return FFProbe::create(array_filter(array('timeout' => $container['configuration.merged']['ffmpeg.ffprobe.timeout'], 'ffprobe.binaries' => $container['configuration.merged']['ffmpeg.ffprobe.binaries'])), $container['logger'], $container['ffmpeg.ffprobe.cache']); } catch (FFMpegExecutableNotFound $e) { throw new RuntimeException('Unable to create FFProbe driver', $e->getCode(), $e); } }); $this['imagine'] = $this->share(function (Pimple $container) { $driver = $container['configuration.merged']['imagine.driver']; switch (true) { case 'imagick' === strtolower($driver): case null === $driver && class_exists('Imagick'): $driver = 'Imagine\\Imagick\\Imagine'; break; case 'gmagick' === strtolower($driver): case null === $driver && class_exists('Gmagick'): $driver = 'Imagine\\Gmagick\\Imagine'; break; case 'gd' === strtolower($driver): case null === $driver && extension_loaded('gd'): $driver = 'Imagine\\Gd\\Imagine'; break; } if (false === class_exists($driver) || false === in_array('Imagine\\Image\\ImagineInterface', class_implements($driver))) { throw new InvalidArgumentException(sprintf('Invalid Imagine driver %s', $driver)); } return new $driver(); }); $this['swftools.driver-container'] = $this->share(function (Pimple $container) { return DriverContainer::create(array_filter(array('pdf2swf.binaries' => $container['configuration.merged']['swftools.pdf2swf.binaries'], 'swfrender.binaries' => $container['configuration.merged']['swftools.swfrender.binaries'], 'swfextract.binaries' => $container['configuration.merged']['swftools.swfextract.binaries'], 'timeout' => $container['configuration.merged']['swftools.timeout'])), $container['logger']); }); $this['swftools.flash-file'] = $this->share(function (Pimple $container) { return new FlashFile($container['swftools.driver-container']); }); $this['swftools.pdf-file'] = $this->share(function (Pimple $container) { return new PDFFile($container['swftools.driver-container']); }); $this['unoconv'] = $this->share(function (Pimple $container) { try { return Unoconv::create(array_filter(array('unoconv.binaries' => $container['configuration.merged']['unoconv.binaries'], 'timeout' => $container['configuration.merged']['unoconv.timeout'])), $container['logger']); } catch (ExecutableNotFoundException $e) { throw new RuntimeException('Unable to create Unoconv driver', $e->getCode(), $e); } }); $this['exiftool.exiftool'] = $this->share(function (Pimple $container) { return new Exiftool($container['logger']); }); $this['exiftool.rdf-parser'] = $this->share(function (Pimple $container) { return new RDFParser(); }); $this['exiftool.reader'] = $this->share(function (Pimple $container) { return new Reader($container['exiftool.exiftool'], $container['exiftool.rdf-parser']); }); $this['exiftool.writer'] = $this->share(function (Pimple $container) { return new Writer($container['exiftool.exiftool']); }); $this['exiftool.preview-extractor'] = $this->share(function (Pimple $container) { return new PreviewExtractor($container['exiftool.exiftool']); }); $this['ghostscript.transcoder'] = $this->share(function (Pimple $container) { try { return Transcoder::create(array_filter(array('gs.binaries' => $container['configuration.merged']['gs.binaries'], 'timeout' => $container['configuration.merged']['gs.timeout'])), $container['logger']); } catch (ExecutableNotFoundException $e) { throw new RuntimeException('Unable to create Unoconv driver', $e->getCode(), $e); } }); $this['mp4box'] = $this->share(function (Pimple $container) { try { return MP4Box::create(array_filter(array('mp4box.binaries' => $container['configuration.merged']['mp4box.binaries'], 'timeout' => $container['configuration.merged']['mp4box.timeout']))); } catch (ExecutableNotFoundException $e) { throw new RuntimeException('Unable to create Unoconv driver', $e->getCode(), $e); } }); $this['mediavorus'] = $this->share(function (Pimple $container) { $ffprobe = null; try { $ffprobe = $container['ffmpeg.ffprobe']; } catch (RuntimeException $e) { } return new MediaVorus($container['exiftool.reader'], $container['exiftool.writer'], $ffprobe); }); }
/** * @expectedException SwfTools\Exception\RuntimeException * @expectedExceptionMessage Unable to load swfextract */ public function testExtractFirstImageNoBinary() { $object = new FlashFile(DriverContainer::create(array('swfextract.binaries' => '/path/to/nowhere'))); $object->extractFirstImage(__DIR__ . '/../../../files/flashfile.swf', '/target'); }
/** * @expectedException SwfTools\Exception\RuntimeException * @expectedExceptionMessage Unable to load pdf2swf */ public function testToSwfNoBinary() { $this->object = new PDFFile(DriverContainer::create(array('pdf2swf.binaries' => '/path/to/nowhere'))); $this->object->toSwf(__DIR__ . '/../../../files/PDF.pdf', $this->destination); }
public function testGetChangePathnameExtension() { $object = new ExtendedFile(DriverContainer::create()); $this->assertEquals('/path/kawabunga.plus', $object->change('/path/kawabunga.png', 'plus')); }