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));
 }
Example #2
0
 public function inspect(Version $fv)
 {
     $fr = $fv->getFileResource();
     $image = Image::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());
 }
 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);
     }
 }
Example #4
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.
     \Log::info('Image Inspector');
     if (\Config::get('concrete.file_manager.images.use_exim_data_to_rotate_images')) {
         $metadata = $image->metadata();
         \Log::info('Checking EXIF 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;
             }
         }
     }
 }
Example #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);
 }
Example #6
0
 public static function add($filename, $prefix, $data = array(), $fsl = 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();
         }
     }
     $f = new self();
     $f->uID = $uID;
     $f->storageLocation = $fsl;
     $f->fDateAdded = new Carbon($date);
     $em = \ORM::entityManager('core');
     $em->persist($f);
     $em->flush();
     $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;
 }
Example #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;
 }
 /**
  * {@inheritDoc}
  */
 public function getListingThumbnailImage()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getListingThumbnailImage', array());
     return parent::getListingThumbnailImage();
 }
Example #9
0
 public static function add(\Concrete\Core\File\File $file, $filename, $prefix, $data = array())
 {
     $u = new User();
     $uID = isset($data['uID']) && $data['uID'] > 0 ? $data['uID'] : $u->getUserID();
     if ($uID < 1) {
         $uID = 0;
     }
     $fvTitle = isset($data['fvTitle']) ? $data['fvTitle'] : '';
     $fvDescription = isset($data['fvDescription']) ? $data['fvDescription'] : '';
     $fvTags = isset($data['fvTags']) ? Version::cleanTags($data['fvTags']) : '';
     $fvIsApproved = isset($data['fvIsApproved']) ? $data['fvIsApproved'] : '1';
     $db = Database::get();
     $dh = Core::make('helper/date');
     $date = new Carbon($dh->getOverridableNow());
     $fv = new static();
     $fv->fvFilename = $filename;
     $fv->fvPrefix = $prefix;
     $fv->fvDateAdded = $date;
     $fv->fvIsApproved = (bool) $fvIsApproved;
     $fv->fvApproverUID = $uID;
     $fv->fvAuthorUID = $uID;
     $fv->fvActivateDateTime = $date;
     $fv->fvTitle = $fvTitle;
     $fv->fvDescription = $fvDescription;
     $fv->fvTags = $fvTags;
     $fv->file = $file;
     $fv->fvID = 1;
     $em = \ORM::entityManager('core');
     $em->persist($fv);
     $em->flush();
     $fve = new \Concrete\Core\File\Event\FileVersion($fv);
     Events::dispatch('on_file_version_add', $fve);
     return $fv;
 }
Example #10
0
 public function getFilePath(FileVersion $fv)
 {
     $prefix = $fv->getPrefix();
     $filename = $fv->getFileName();
     $hi = Core::make('helper/file');
     $ii = Core::make('helper/concrete/file');
     $filename = $hi->replaceExtension($filename, 'jpg');
     return REL_DIR_FILES_THUMBNAILS . '/' . $this->getDirectoryName() . $ii->prefix($prefix, $filename);
 }
Example #11
0
 /**
  * Get the main image path ignoring the thumbnail requirements
  *
  * @param \Concrete\Core\File\Version $file_version
  * @param \Concrete\Core\File\Image\Thumbnail\Type\Version $thumbnail
  * @return string
  */
 protected function getDefaultPath(Version $file_version, ThumbnailVersion $thumbnail, 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);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getJSONObject()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getJSONObject', array());
     return parent::getJSONObject();
 }
 public function process(Version $version)
 {
     $fr = $version->getFileResource();
     $image = \Image::load($fr->read());
     $version->updateContents($image->get('jpg', array('jpeg_quality' => $this->getQuality())));
 }
Example #14
0
 public function getListingThumbnailImage()
 {
     return parent::getListingThumbnailImage();
 }