コード例 #1
0
 /**
  * @param Media $media
  */
 public function prepareMedia(Media $media)
 {
     parent::prepareMedia($media);
     if ($media->getContent()) {
         $imageInfo = getimagesize($media->getContent());
         $width = $imageInfo[0];
         $height = $imageInfo[1];
         $media->setMetadataValue('original_width', $width)->setMetadataValue('original_height', $height);
     }
 }
コード例 #2
0
 public function prepareMedia(Media $media)
 {
     $url = $media->getUrl();
     $media->setUuid(uniqid());
     parent::prepareMedia($media);
     if ($media->getContent() instanceof File) {
         // if media already has it’s local path ($url) then i don’t want parent to overwrite it
         if ($url && "." !== $url[strlen($url) - 1] && $url === parse_url($url, PHP_URL_PATH)) {
             $media->setUrl($url);
         }
         $dirname = dirname($media->getUrl());
         $ext = pathinfo($media->getUrl(), PATHINFO_EXTENSION);
         $filename = $this->slugifier->slugify(basename($media->getUrl(), $ext)) . ($ext ? ".{$ext}" : "");
         $url = implode('/', [$dirname, $filename]);
         $this->setMediaUrl($media, $url);
     }
 }