Ejemplo n.º 1
0
 public function testMediaChangeDifferentAdapter()
 {
     Process::config(['image' => new GenericMock(null), 'video' => new GenericNameMock(null)]);
     $source = fopen("{$this->_files}/video_theora_notag.ogv", 'r');
     $storeFrom = fopen("{$this->_files}/image_jpg.jpg", 'r');
     $adapter = new GenericNameMock($source);
     $adapter->storeCopyFromStream = $storeFrom;
     $media = new Video(compact('adapter'));
     $result = $media->convert('image/jpg');
     $this->assertInstanceOf('\\mm\\Media\\Process\\Image', $result);
     fclose($source);
     fclose($storeFrom);
 }
Ejemplo n.º 2
0
 public function testMediaFactoryTransplantAdapter()
 {
     $result = Process::factory(['adapter' => new GenericMock(null), 'source' => 'image/jpeg']);
     $this->assertInstanceOf('\\mm\\Media\\Process\\Image', $result);
 }
Ejemplo n.º 3
0
if ($hasFileinfo) {
    Type::config('magic', ['adapter' => 'Fileinfo']);
} else {
    Type::config('magic', ['adapter' => 'Freedesktop', 'file' => __DIR__ . '/data/magic.db']);
}
if ($cached = $cacheRead('mime_type_glob')) {
    Type::config('glob', ['adapter' => 'Memory']);
    foreach ($cached as $item) {
        Type::$glob->register($item);
    }
} else {
    Type::config('glob', ['adapter' => 'Freedesktop', 'file' => __DIR__ . '/data/glob.db']);
    $cacheWrite('mime_type_glob', Type::$glob->to('array'));
}
/*
 * Configure the adpters to be used by the media process class. Adjust this
 * mapping of media names to adapters according to your environment. For example:
 * most PHP installations have GD enabled thus should choose the `Gd` adapter for
 * image transformations. However the `Imagick` adapter may be more desirable
 * in other cases and also supports transformations for documents.
 */
use mm\Media\Process;
Process::config(['document' => $hasImagick ? 'Imagick' : null, 'image' => $hasImagick ? 'Imagick' : 'Gd']);
/*
 * Configure the adpters to be used by the media info class. Adjust this
 * mapping of media names to adapters according to your environment. In contrast
 * to `Process` which operates only with one adapter per media type
 * `Info` can use multiple adapters per media type.
 */
use mm\Media\Info;
Info::config(['image' => $hasImagick ? ['ImageBasic', 'Imagick'] : ['ImageBasic']]);
Ejemplo n.º 4
0
 /**
  * Converts the media to given MIME type.
  *
  * @param string $mimeType
  * @return boolean|object false on error or a Media object on success
  */
 public function convert($mimeType)
 {
     $this->_adapter->convert($mimeType);
     if ($this->name() != Type::guessName($mimeType)) {
         // Crosses media (i.e. document -> image).
         $config = Process::config();
         if ($config[$this->name()] == $config[Type::guessName($mimeType)]) {
             // ...but using the same adapter.
             $media = Process::factory(['source' => $mimeType, 'adapter' => $this->_adapter]);
         } else {
             // ...using different adapters.
             $handle = fopen('php://temp', 'w+');
             $this->_adapter->store($handle);
             $media = Process::factory(['source' => $handle]);
             fclose($handle);
         }
         return $media;
     }
     // Stays entirely in same media (i.e. image -> image).
     return $this;
 }