Ejemplo n.º 1
0
 public function testGuessTypeFile()
 {
     $files = ['video_h264_qt_tag.mp4' => 'video/mp4'];
     foreach ($files as $file => $mimeType) {
         $this->assertEquals($mimeType, Type::guessType("{$this->_files}/{$file}"), "File `{$file}`.");
     }
 }
Ejemplo n.º 2
0
 protected function _load($handle)
 {
     rewind($handle);
     $this->_object = $handle;
     $this->_objectTemp = $this->_tempFile();
     file_put_contents($this->_objectTemp, $handle);
     $this->_objectType = $this->_type(Type::guessType($handle));
     return true;
 }
Ejemplo n.º 3
0
 public function testConvertToVideo()
 {
     $source = fopen("{$this->_files}/video_theora_comments.ogv", 'r');
     $target = fopen('php://temp', 'wb');
     $subject = new FfmpegShell($source);
     $subject->convert('video/mpeg');
     $result = $subject->store($target);
     $this->assertTrue($result);
     $this->assertEquals('video/mpeg', Type::guessType($target));
     fclose($source);
     fclose($target);
 }
Ejemplo n.º 4
0
 public function testConvertImageToImage()
 {
     $source = fopen("{$this->_files}/image_png.png", 'r');
     $target = fopen('php://temp', 'wb');
     $subject = new Gd($source);
     $subject->convert('image/jpeg');
     $result = $subject->store($target);
     $this->assertTrue($result);
     $this->assertEquals('image/jpeg', Type::guessType($target));
     fclose($source);
     fclose($target);
 }
Ejemplo n.º 5
0
 public function testConvert()
 {
     $source = fopen("{$this->_files}/audio_vorbis_comments.ogg", 'r');
     $target = fopen('php://temp', 'wb');
     $subject = new SoxShell($source);
     $subject->convert('audio/x-wav');
     $result = $subject->store($target);
     $this->assertTrue($result);
     $this->assertEquals('audio/x-wav', Type::guessType($target));
     fclose($source);
     fclose($target);
 }
Ejemplo n.º 6
0
 public function __construct($handle)
 {
     rewind($handle);
     $this->_object = new ImagickCore();
     $this->_object->readImageFile($handle);
     // For sequences reset iterator to get to first one first.
     if ($this->_object->getNumberImages() > 1) {
         $this->_object->setFirstIterator();
     }
     $mimeType = Type::guessType($handle);
     if (!isset($this->_formatMap[$mimeType])) {
         throw new OutOfBoundsException("MIME type `{$mimeType}` cannot be mapped to a format.");
     }
     // We need to explictly `setFormat()` here, otherwise `getFormat()` returns `null`.
     $this->_object->setFormat($this->_formatMap[$mimeType]);
 }
Ejemplo n.º 7
0
 public function __construct($handle)
 {
     $mimeType = Type::guessType($handle);
     if (!isset($this->_formatMap[$mimeType])) {
         throw new OutOfBoundsException("Could not map MIME-type `{$mimeType}` to format.");
     }
     $this->_format = $this->_formatMap[$mimeType];
     $this->_object = imageCreateFromString(stream_get_contents($handle));
     if (!$this->_isResource($this->_object)) {
         throw new Exception("Was not able to create image from handle.");
     }
     if (imageIsTrueColor($this->_object)) {
         imageAlphaBlending($this->_object, false);
         imageSaveAlpha($this->_object, true);
     }
 }
Ejemplo n.º 8
0
 /**
  * Convert the track using the best possible means
  * @param  string $filename The new filename
  * @return object           New Media Object
  */
 public function convertMultiple($newFilename, $codecs = array())
 {
     if (empty($codecs)) {
         return false;
     }
     $intermediary = $this->createIntermediaries();
     //generate wav form png
     if (isset($this->image)) {
         $waveform = new \Jasny\Audio\Waveform($intermediary['wav']['path'], array("width" => 700));
         $waveform->save("png", $this->image);
     }
     //generate final file
     foreach ($codecs as $codec) {
         $parts = pathinfo($newFilename);
         $base = dirname($newFilename);
         $file = $base . "/" . $parts['filename'] . "." . $codec;
         $extension = Type::guessExtension($file);
         if (empty($extension) || $extension == "bin") {
             $extension = $codec;
         }
         $mime = Type::guessType($file);
         foreach ($this->getDrivers() as $driver) {
             $class = "Media\\Driver\\Drivers\\" . $driver;
             if ($driver == "AsteriskShell") {
                 $i = $intermediary['sln'];
             } else {
                 $i = $intermediary['wav'];
             }
             if ($class::installed() && $class::isCodecSupported($extension, "out")) {
                 $driver = new $class($i['path'], $i['extension'], $i['mime']);
                 $driver->convert($file, $extension, $mime);
                 if (!file_exists($file)) {
                     throw new \Exception("File was not converted");
                 }
                 break;
             }
         }
     }
     if (!empty($intermediary['wav']['path']) && file_exists($intermediary['wav']['path'])) {
         unlink($intermediary['wav']['path']);
     }
     if (!empty($intermediary['sln']['path']) && file_exists($intermediary['sln']['path'])) {
         unlink($intermediary['sln']['path']);
     }
     unset($intermediary);
     return file_exists($newFilename);
 }
Ejemplo n.º 9
0
 public function testPassthru()
 {
     $source = fopen("{$this->_files}/image_png.png", 'r');
     $target = fopen('php://temp', 'wb');
     $subject = new Imagick($source);
     $subject->passthru('setFormat', 'jpeg');
     $result = $subject->store($target);
     $this->assertTrue($result);
     $this->assertEquals('image/jpeg', Type::guessType($target));
     fclose($source);
     fclose($target);
 }
Ejemplo n.º 10
0
 public function testGuessTypePreferredTypes()
 {
     $result = Type::guessType('test.ogg');
     $this->assertEquals('audio/ogg', $result);
 }