Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function read($filename)
 {
     $meta = new ValueBag();
     foreach ($this->readers as $reader) {
         if ($reader->available() && $reader->supports($filename)) {
             $meta->merge($reader->read($filename));
         }
     }
     return $meta;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function read($filename)
 {
     $meta = new ValueBag();
     try {
         $imageInfo = $this->analyzer->analyze($filename);
         $meta->set('image.width', new MetaValue($imageInfo->getWidth()))->set('image.height', new MetaValue($imageInfo->getHeight()))->set('image.format', new MetaValue($imageInfo->getFormat()))->set('image.type', new MetaValue($imageInfo->getType()))->set('image.colorspace', new MetaValue($imageInfo->getColorspace()))->set('image.depth', new MetaValue($imageInfo->getDepth()));
         if ($imageInfo->getColors()) {
             $meta->set('image.colors', new MetaValue($imageInfo->getColors()));
         }
         if ($imageInfo->getQuality()) {
             $meta->set('image.quality', new MetaValue($imageInfo->getQuality()));
         }
         if ($imageInfo->getCompression()) {
             $meta->set('image.compression', new MetaValue($imageInfo->getCompression()));
         }
         if ($imageInfo->getResolution()) {
             $meta->set('image.resolution', new MetaValue($imageInfo->getResolution()));
         }
         if ($imageInfo->getUnits()) {
             $meta->set('image.units', new MetaValue($imageInfo->getUnits()));
         }
         if ($imageInfo->getProfiles()) {
             $meta->set('image.profiles', new MetaValue(implode(',', $imageInfo->getProfiles())));
         }
     } catch (\Exception $e) {
     }
     return $meta;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function read($filename)
 {
     $meta = new ValueBag();
     try {
         $infos = $this->pdfFile->getInfo($filename);
         foreach ($infos as $key => $value) {
             $meta->set(strtolower("pdfinfo.{$key}"), new MetaValue($value));
         }
     } catch (\Exception $e) {
     }
     return $meta;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function read($filename)
 {
     $meta = new ValueBag();
     try {
         $result = @\exif_read_data($filename, '', true);
     } catch (\Exception $e) {
         return $meta;
     }
     if (!empty($result['IFD0'])) {
         foreach ($result['IFD0'] as $key => $value) {
             $meta->set("exif.{$key}", new MetaValue($value));
         }
     }
     return $meta;
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function read($filename)
 {
     $meta = new ValueBag();
     try {
         $fileEntity = $this->reader->reset()->files($filename)->first();
     } catch (\Exception $e) {
         return $meta;
     }
     if ($fileEntity->getMetadatas()->containsKey('File:ImageWidth')) {
         $meta->set('image.width', new MetaValue((int) $fileEntity->getMetadatas()->get('File:ImageWidth')->getValue()->asString()));
     } elseif ($fileEntity->getMetadatas()->containsKey('PNG:ImageWidth')) {
         $meta->set('image.width', new MetaValue((int) $fileEntity->getMetadatas()->get('PNG:ImageWidth')->getValue()->asString()));
     }
     if ($fileEntity->getMetadatas()->containsKey('File:ImageHeight')) {
         $meta->set('image.height', new MetaValue((int) $fileEntity->getMetadatas()->get('File:ImageHeight')->getValue()->asString()));
     } elseif ($fileEntity->getMetadatas()->containsKey('PNG:ImageHeight')) {
         $meta->set('image.height', new MetaValue((int) $fileEntity->getMetadatas()->get('PNG:ImageHeight')->getValue()->asString()));
     }
     foreach ($fileEntity->getMetadatas() as $metadata) {
         /* @var $metadata Metadata */
         if (ValueInterface::TYPE_BINARY === $metadata->getValue()->getType()) {
             continue;
         }
         $groupName = $metadata->getTag()->getGroupName();
         $name = $metadata->getTag()->getName();
         $value = (string) $metadata->getValue();
         if ($groupName === 'System' || !ctype_print($value)) {
             continue;
         }
         $path = "{$groupName}.{$name}";
         $meta->set($path, new MetaValue($value));
     }
     return $meta;
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function read($filename)
 {
     $meta = new ValueBag();
     try {
         $zip = new \ZipArchive();
         $result = $zip->open($filename);
         if ($result === true) {
             if ($zip->comment) {
                 $meta->set('zip.comment', new MetaValue($zip->comment));
             }
             if ($zip->numFiles) {
                 $meta->set('zip.numFiles', new MetaValue($zip->numFiles));
             }
             if ($zip->status) {
                 $meta->set('zip.status', new MetaValue($zip->status));
             }
             $zip->close();
         }
     } catch (\Exception $e) {
     }
     return $meta;
 }
Ejemplo n.º 7
0
 public function testCount()
 {
     $metaBag = new ValueBag(['foo' => 1, 'bar' => 2, 'baz' => 3]);
     $this->assertSame(3, $metaBag->count());
     $this->assertCount(3, $metaBag);
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function read($filename)
 {
     $meta = new ValueBag();
     try {
         $format = $this->ffprobe->format($filename);
         if ($format->has('format_name')) {
             $meta->set('media.format_name', new MetaValue($format->get('format_name')));
         }
         if ($format->has('format_long_name')) {
             $meta->set('media.format_long_name', new MetaValue($format->get('format_long_name')));
         }
         if ($format->has('duration')) {
             $meta->set('media.duration', new MetaValue($format->get('duration')));
         }
         if ($format->has('bit_rate')) {
             $meta->set('media.bit_rate', new MetaValue($format->get('bit_rate')));
         }
         if ($format->has('width')) {
             $meta->set('media.width', new MetaValue($format->get('width')));
         }
         if ($format->has('height')) {
             $meta->set('media.height', new MetaValue($format->get('height')));
         }
         if ($format->has('nb_streams')) {
             $meta->set('media.number_of_streams', new MetaValue($format->get('nb_streams')));
         }
         $streams = $this->ffprobe->streams($filename);
         foreach ($streams as $stream) {
             $index = $stream->get('index');
             $prefix = 'stream_' . $index;
             $type = 'media';
             if ($stream->isVideo()) {
                 $type = 'video';
             } elseif ($stream->isAudio()) {
                 $type = 'audio';
             }
             if ($stream->has('codec_type')) {
                 $meta->set("{$type}.{$prefix}.codec_type", new MetaValue($stream->get('codec_type')));
             }
             if ($stream->has('codec_name')) {
                 $meta->set("{$type}.{$prefix}.codec_name", new MetaValue($stream->get('codec_name')));
             }
             if ($stream->has('codec_long_name')) {
                 $meta->set("{$type}.{$prefix}.codec_long_name", new MetaValue($stream->get('codec_long_name')));
             }
             if ($stream->has('codec_time_base')) {
                 $meta->set("{$type}.{$prefix}.codec_time_base", new MetaValue($stream->get('codec_time_base')));
             }
             if ($stream->has('codec_tag_string')) {
                 $meta->set("{$type}.{$prefix}.codec_tag", new MetaValue($stream->get('codec_tag_string')));
             }
             if ($stream->has('bit_rate')) {
                 $meta->set("{$type}.{$prefix}.bit_rate", new MetaValue($stream->get('bit_rate')));
             }
             if ($stream->has('display_aspect_ration')) {
                 $meta->set("{$type}.{$prefix}.aspect_ratio", new MetaValue($stream->get('display_aspect_ratio')));
             }
             if ($stream->has('avg_frame_rate')) {
                 $meta->set("{$type}.{$prefix}.frame_rate", new MetaValue($stream->get('avg_frame_rate')));
             }
             if ($stream->has('bits_per_sample')) {
                 $meta->set("{$type}.{$prefix}.bits_per_sample", new MetaValue($stream->get('bits_per_sample')));
             }
             if ($stream->has('channels')) {
                 $meta->set("{$type}.{$prefix}.channels", new MetaValue($stream->get('channels')));
             }
         }
     } catch (\Exception $e) {
     }
     return $meta;
 }