/** * Create all the thumbnails for a picture. * * @param string $path Path to the file. This can be a virtual path or a absolute path. * @param string $fileNamePlain Plain file name without extension * @param string $fileExtension Extension of the file * @param \ImageManager $imageManager * * <code> * <?php * \Cx\Core_Modules\MediaBrowser\Model\FileSystem::createThumbnail( * 'files/', * 'Django, * 'jpg', * new ImageManager() // Please recycle the instance and don't create a new anonymous instance for each call. * // This is just a simple example. * ); * ?> * </code> * * @return array With all thumbnail types and if they were generated successfully. */ public static function createThumbnail($path, $fileNamePlain, $fileExtension, \ImageManager $imageManager, $generateThumbnailByRatio = false) { $success = array(); foreach (UploaderConfiguration::getInstance()->getThumbnails() as $thumbnail) { if (\Cx\Lib\FileSystem\FileSystem::exists(MediaSourceManager::getAbsolutePath($path) . $fileNamePlain . $thumbnail['value'] . '.' . $fileExtension)) { $success[$thumbnail['value']] = self::THUMBNAIL_GENERATOR_NEUTRAL; continue; } if ($imageManager->_createThumb(MediaSourceManager::getAbsolutePath($path) . '/', '', $fileNamePlain . '.' . $fileExtension, $thumbnail['size'], $thumbnail['quality'], $fileNamePlain . $thumbnail['value'] . '.' . $fileExtension, $generateThumbnailByRatio)) { $success[$thumbnail['value']] = self::THUMBNAIL_GENERATOR_SUCCESS; continue; } $success[$thumbnail['value']] = self::THUMBNAIL_GENERATOR_FAIL; } return $success; }
/** * Create all the thumbnails for a picture. * * @param string $path Path to the file. This can be a virtual path or a absolute path. * @param string $fileNamePlain Plain file name without extension * @param string $fileExtension Extension of the file * @param \ImageManager $imageManager * * <code> * <?php * \Cx\Core_Modules\MediaBrowser\Model\FileSystem::createThumbnail( * 'files/', * 'Django, * 'jpg', * new ImageManager() // Please recycle the instance and don't create a new anonymous instance for each call. * // This is just a simple example. * ); * ?> * </code> * * @param bool $generateThumbnailByRatio * @param bool $force Force creation of new Thumbnails. This overwrites any existing thumbnail. * * @return array Array with the relative paths to the thumbnails. */ public function createThumbnail($path, $fileNamePlain, $fileExtension, \ImageManager $imageManager, $generateThumbnailByRatio = false, $force = false) { $thumbnails = array(); foreach ($this->getThumbnails() as $thumbnail) { if ($force) { \Cx\Lib\FileSystem\FileSystem::delete_file(MediaSourceManager::getAbsolutePath($path) . '/' . $fileNamePlain . $thumbnail['value'] . '.' . $fileExtension); } elseif (\Cx\Lib\FileSystem\FileSystem::exists(MediaSourceManager::getAbsolutePath($path) . '/' . $fileNamePlain . $thumbnail['value'] . '.' . $fileExtension)) { $thumbnails[] = $fileNamePlain . $thumbnail['value'] . '.' . $fileExtension; continue; } if ($imageManager->_createThumb(MediaSourceManager::getAbsolutePath($path) . '/', '', $fileNamePlain . '.' . $fileExtension, $thumbnail['size'], $thumbnail['quality'], $fileNamePlain . $thumbnail['value'] . '.' . $fileExtension, $generateThumbnailByRatio)) { $thumbnails[] = $fileNamePlain . $thumbnail['value'] . '.' . $fileExtension; continue; } } return $thumbnails; }