public function importFiles($fromPath, $computeThumbnails = true) { $fh = new Importer(); if (!$computeThumbnails) { $fh->setRescanThumbnailsOnImport(false); $helper = Core::make('helper/file'); } $contents = Core::make('helper/file')->getDirectoryContents($fromPath); foreach ($contents as $filename) { if (!is_dir($filename)) { $fv = $fh->import($fromPath . '/' . $filename, $filename); if (!$computeThumbnails) { $types = \Concrete\Core\File\Image\Thumbnail\Type\Type::getVersionList(); foreach ($types as $type) { // since we provide the thumbnails, we're going to get a list of thumbnail types // and loop through them, assigning them to all the files. $thumbnailPath = $fromPath . '/' . $type->getHandle() . '/' . $filename; if (file_exists($thumbnailPath)) { $fv->importThumbnail($type, $thumbnailPath); } } } } } }
public function view() { $types = \Concrete\Core\File\Image\Thumbnail\Type\Type::getVersionList(); $this->set('types', $types); $version = $this->file->getVersion($this->request->request->get('fvID')); $this->set('version', $version); }
public static function getByHandle($handle) { $list = Type::getVersionList(); foreach ($list as $version) { if ($version->getHandle() == $handle) { return $version; } } }
public function rescanThumbnails() { if ($this->fvType != \Concrete\Core\File\Type\Type::T_IMAGE) { return false; } $types = Type::getVersionList(); $fr = $this->getFileResource(); try { $image = \Image::load($fr->read()); $mimetype = $fr->getMimeType(); foreach ($types as $type) { // delete the file if it exists $this->deleteThumbnail($type); if ($this->getAttribute('width') <= $type->getWidth()) { continue; } $filesystem = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject(); $height = $type->getHeight(); $thumbnailMode = ImageInterface::THUMBNAIL_OUTBOUND; if (!$height) { $height = $type->getWidth(); $thumbnailMode = ImageInterface::THUMBNAIL_INSET; } $thumbnail = $image->thumbnail(new \Imagine\Image\Box($type->getWidth(), $height), $thumbnailMode); $thumbnailPath = $type->getFilePath($this); $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; } $filesystem->write($thumbnailPath, $thumbnail->get($thumbnailType, $thumbnailOptions), array('visibility' => AdapterInterface::VISIBILITY_PUBLIC, 'mimetype' => $mimetype)); if ($type->getHandle() == \Config::get('concrete.icons.file_manager_listing.handle')) { $this->fvHasListingThumbnail = true; } if ($type->getHandle() == \Config::get('concrete.icons.file_manager_detail.handle')) { $this->fvHasDetailThumbnail = true; } unset($thumbnail); unset($filesystem); } } catch (ImagineInvalidArgumentException $e) { return false; } }
public function rescanThumbnails() { if ($this->fvType != \Concrete\Core\File\Type\Type::T_IMAGE) { return false; } $app = Facade::getFacadeApplication(); $imagewidth = $this->getAttribute('width'); $imageheight = $this->getAttribute('height'); $types = Type::getVersionList(); $fr = $this->getFileResource(); try { $mimetype = $fr->getMimeType(); $imageLibrary = \Image::getFacadeRoot(); switch ($mimetype) { case 'image/svg+xml': case 'image/svg-xml': if ($imageLibrary instanceof \Imagine\Gd\Imagine) { try { $imageLibrary = $app->make('image/imagick'); } catch (\Exception $x) { return false; } } break; } $image = $imageLibrary->load($fr->read()); /* @var \Imagine\Imagick\Image $image */ if (!$imagewidth) { $imagewidth = $image->getSize()->getWidth(); } if (!$imageheight) { $imageheight = $image->getSize()->getHeight(); } foreach ($types as $type) { // delete the file if it exists $this->deleteThumbnail($type); // if image is smaller than width, don't create thumbnail if ($imagewidth < $type->getWidth()) { continue; } // if image is the same width as thumbnail, and there's no thumbnail height set, // or if a thumbnail height set and the image has a smaller or equal height, don't create thumbnail if ($imagewidth == $type->getWidth() && (!$type->getHeight() || $imageheight <= $type->getHeight())) { continue; } // otherwise file is bigger than thumbnail in some way, proceed to create thumbnail $filesystem = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject(); $height = $type->getHeight(); if ($height) { $size = new Box($type->getWidth(), $height); $thumbnailMode = ImageInterface::THUMBNAIL_OUTBOUND; } else { $size = $image->getSize()->widen($type->getWidth()); $thumbnailMode = ImageInterface::THUMBNAIL_INSET; } $thumbnail = $image->thumbnail($size, $thumbnailMode); $thumbnailPath = $type->getFilePath($this); $thumbnailOptions = []; switch ($mimetype) { case 'image/jpeg': $thumbnailType = 'jpeg'; $thumbnailOptions = ['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; } $filesystem->write($thumbnailPath, $thumbnail->get($thumbnailType, $thumbnailOptions), ['visibility' => AdapterInterface::VISIBILITY_PUBLIC, 'mimetype' => $mimetype]); if ($type->getHandle() == \Config::get('concrete.icons.file_manager_listing.handle')) { $this->fvHasListingThumbnail = true; } if ($type->getHandle() == \Config::get('concrete.icons.file_manager_detail.handle')) { $this->fvHasDetailThumbnail = true; } unset($size); unset($thumbnail); unset($filesystem); } } catch (\Imagine\Exception\InvalidArgumentException $e) { return false; } catch (\Imagine\Exception\RuntimeException $e) { return false; } }
public function rescanThumbnails() { $types = Type::getVersionList(); foreach ($types as $type) { $fr = $this->getFileResource(); // delete the file if it exists $this->deleteThumbnail($type); if ($this->getAttribute('width') <= $type->getWidth()) { continue; } $image = \Image::load($fr->read()); $filesystem = $this->getFile()->getFileStorageLocationObject()->getFileSystemObject(); $height = $type->getHeight(); $thumbnailMode = ImageInterface::THUMBNAIL_OUTBOUND; if (!$height) { $height = $type->getWidth(); $thumbnailMode = ImageInterface::THUMBNAIL_INSET; } $thumbnail = $image->thumbnail(new \Imagine\Image\Box($type->getWidth(), $height), $thumbnailMode); $thumbnailPath = $type->getFilePath($this); $o = new \stdClass(); $o->visibility = AdapterInterface::VISIBILITY_PUBLIC; $o->mimetype = 'image/jpeg'; $filesystem->write($thumbnailPath, $thumbnail->get('jpg', array('jpeg_quality' => 60)), array('visibility' => AdapterInterface::VISIBILITY_PUBLIC, 'mimetype' => 'image/jpeg')); if ($type->getHandle() == \Config::get('concrete.icons.file_manager_listing.handle')) { $this->fvHasListingThumbnail = true; } if ($type->getHandle() == \Config::get('concrete.icons.file_manager_detail.handle')) { $this->fvHasDetailThumbnail = true; } } }