public function process(Version $version)
 {
     $fr = $version->getFileResource();
     $image = \Image::load($fr->read());
     $fr = $version->getFileResource();
     $width = $this->getMaxWidth();
     $height = $this->getMaxHeight();
     $mode = $this->getConstraintMode();
     $thumbnail = $image->thumbnail(new Box($width, $height), $mode);
     $mimetype = $fr->getMimeType();
     $thumbnailOptions = array();
     switch ($mimetype) {
         case 'image/jpeg':
             $thumbnailType = 'jpeg';
             $thumbnailOptions = array('jpeg_quality' => \Config::get('concrete.misc.default_jpeg_image_compression'));
             break;
         case 'image/png':
             $thumbnailType = 'png';
             break;
         case 'image/gif':
             $thumbnailType = 'gif';
             break;
         case 'image/xbm':
             $thumbnailType = 'xbm';
             break;
         case 'image/vnd.wap.wbmp':
             $thumbnailType = 'wbmp';
             break;
         default:
             $thumbnailType = 'png';
             break;
     }
     $version->updateContents($thumbnail->get($thumbnailType, $thumbnailOptions));
 }
 public function process(Version $version)
 {
     switch ($this->getFormat()) {
         case self::FORMAT_JPEG:
             $extension = 'jpg';
         default:
             $extension = 'jpg';
             break;
     }
     if ($extension) {
         $fr = $version->getFileResource();
         $image = \Image::load($fr->read());
         $filename = $version->getFileName();
         $service = \Core::make('helper/file');
         $newFilename = $service->replaceExtension($filename, $extension);
         $version->updateContents($image->get($extension));
         $version->rename($newFilename);
     }
 }
Exemplo n.º 3
0
 public function inspect(Version $fv)
 {
     $fr = $fv->getFileResource();
     $imagine = Core::make(Image::getFacadeAccessor());
     if (\Config::get('concrete.file_manager.images.use_exim_data_to_rotate_images')) {
         try {
             $imagine->setMetadataReader(new ExifMetadataReader());
         } catch (NotSupportedException $e) {
         }
     }
     $image = $imagine->load($fr->read());
     $data = $image->getSize();
     // sets an attribute - these file attribute keys should be added
     // by the system and "reserved"
     $at1 = FileAttributeKey::getByHandle('width');
     $at2 = FileAttributeKey::getByHandle('height');
     $fv->setAttribute($at1, $data->getWidth());
     $fv->setAttribute($at2, $data->getHeight());
     // Set image aspect ratio if we can.
     if (\Config::get('concrete.file_manager.images.use_exim_data_to_rotate_images')) {
         $metadata = $image->metadata();
         if (isset($metadata['ifd0.Orientation'])) {
             \Log::info('EXIF data found: ' . $metadata['ifd0.Orientation']);
             switch ($metadata['ifd0.Orientation']) {
                 case 3:
                     $image->rotate(180);
                     $fv->updateContents($image->get($fv->getExtension()));
                     break;
                 case 6:
                     $image->rotate(90);
                     $fv->updateContents($image->get($fv->getExtension()));
                     break;
                 case 8:
                     $image->rotate(-90);
                     $fv->updateContents($image->get($fv->getExtension()));
                     break;
             }
         }
     }
 }
Exemplo n.º 4
0
 public static function add($filename, $prefix, $data = array(), $fsl = false, $folder = false)
 {
     $db = Loader::db();
     $dh = Loader::helper('date');
     $date = $dh->getOverridableNow();
     if (!is_object($fsl)) {
         $fsl = StorageLocation::getDefault();
     }
     $uID = 0;
     $u = new User();
     if (isset($data['uID'])) {
         $uID = $data['uID'];
     } else {
         if ($u->isRegistered()) {
             $uID = $u->getUserID();
         }
     }
     if (!$folder instanceof FileFolder) {
         $filesystem = new Filesystem();
         $folder = $filesystem->getRootFolder();
     }
     $f = new \Concrete\Core\Entity\File\File();
     $f->uID = $uID;
     $f->storageLocation = $fsl;
     $f->fDateAdded = new Carbon($date);
     $f->folderTreeNodeID = $folder->getTreeNodeID();
     $em = \ORM::entityManager();
     $em->persist($f);
     $em->flush();
     $node = \Concrete\Core\Tree\Node\Type\File::add($f, $folder);
     $fv = Version::add($f, $filename, $prefix, $data);
     $f->versions->add($fv);
     $fve = new \Concrete\Core\File\Event\FileVersion($fv);
     Events::dispatch('on_file_add', $fve);
     $entities = $u->getUserAccessEntityObjects();
     $hasUploader = false;
     foreach ($entities as $obj) {
         if ($obj instanceof FileUploaderPermissionAccessEntity) {
             $hasUploader = true;
         }
     }
     if (!$hasUploader) {
         $u->refreshUserGroups();
     }
     return $fv;
 }
Exemplo n.º 5
0
 public function inspect(Version $fv)
 {
     $at1 = FileAttributeKey::getByHandle('duration');
     $at2 = FileAttributeKey::getByHandle('width');
     $at3 = FileAttributeKey::getByHandle('height');
     // we killed $path here because the file might be hosted remotely.
     // @TODO add in support for streams through the $filesystem object.
     $cf = Core::make('helper/concrete/file');
     $fs = $fv->getFile()->getFileStorageLocationObject()->getFileSystemObject();
     $fp = $fs->readStream($cf->prefix($fv->getPrefix(), $fv->getFileName()));
     @fseek($fp, 27);
     $onMetaData = fread($fp, 10);
     //if ($onMetaData != 'onMetaData') exit('No meta data available in this file! Fix it using this tool: http://www.buraks.com/flvmdi/');
     @fseek($fp, 16, SEEK_CUR);
     $duration = array_shift(unpack('d', strrev(fread($fp, 8))));
     @fseek($fp, 8, SEEK_CUR);
     $width = array_shift(unpack('d', strrev(fread($fp, 8))));
     @fseek($fp, 9, SEEK_CUR);
     $height = array_shift(unpack('d', strrev(fread($fp, 8))));
     $fv->setAttribute($at1, $duration);
     $fv->setAttribute($at2, $width);
     $fv->setAttribute($at3, $height);
 }
Exemplo n.º 6
0
 /**
  * @param mixed $version
  */
 public function setVersion(Version $version)
 {
     $this->fID = $version->getFileID();
     $this->fvID = $version->getFileVersionID();
 }
Exemplo n.º 7
0
 public function getFilePath(FileVersion $fv)
 {
     $prefix = $fv->getPrefix();
     $filename = $fv->getFileName();
     $hi = Core::make('helper/file');
     $ii = Core::make('helper/concrete/file');
     $f1 = REL_DIR_FILES_THUMBNAILS . '/' . $this->getDirectoryName() . $ii->prefix($prefix, $filename);
     $f2 = REL_DIR_FILES_THUMBNAILS . '/' . $this->getDirectoryName() . $ii->prefix($prefix, $hi->replaceExtension($filename, 'jpg'));
     // 5.7.4 keeps extension; older sets it to .jpg
     $filesystem = $fv->getFile()->getFileStorageLocationObject()->getFileSystemObject();
     if ($filesystem->has($f1)) {
         return $f1;
     }
     //fallback
     return $f2;
 }
Exemplo n.º 8
0
 /**
  * Get the main image path ignoring the thumbnail requirements
  *
  * @param \Concrete\Core\Entity\File\Version $file_version
  * @param \Concrete\Core\File\Image\Thumbnail\Type\Version $thumbnail
  * @return string
  */
 protected function getDefaultPath(Version $file_version, ThumbnailVersion $thumbnail, \Concrete\Core\Entity\File\StorageLocation\StorageLocation $storage, ConfigurationInterface $configuration)
 {
     $cf = $this->app->make('helper/concrete/file');
     if ($configuration->hasPublicURL()) {
         $file = $cf->prefix($file_version->getPrefix(), $file_version->getFileName());
         if ($configuration instanceof DeferredConfigurationInterface) {
             return $file;
         }
         return $configuration->getPublicURLToFile($file);
     }
 }