/**
  * testDir creating directory
  */
 public function testDirectoryCreate()
 {
     $path =& $this->path;
     $recursive = true;
     $force = true;
     $this->assertTrue(DirectoryHelper::create($path, $recursive, $force));
 }
예제 #2
0
 public function init()
 {
     DirectoryHelper::create(\Yii::getAlias($this->imagesPath), true);
     $this->imagesPath = \Yii::getAlias($this->imagesPath);
     $this->registerDependencies();
     $this->initBaseTemplate();
     return parent::init();
 }
 protected function saveImageInCategory($category, $path, $name)
 {
     // Path to image
     $saveImagePath = $this->owner->imagesPath;
     $categoryOptions = $this->owner->categories;
     $defaultCategoriesSize = $this->owner->baseTemplate;
     if (!array_key_exists($category, $categoryOptions['category'])) {
         throw new \UnexpectedValueException(" Category with name {$category} not specified.");
     }
     // New path to image
     $newPath = implode(DIRECTORY_SEPARATOR, [$saveImagePath, $category]);
     // Specifies the full path to the category, for the derived class from BaseName
     $this->name->pathToCatory = $newPath;
     // New image name created with class BaseName
     $imageName = $name;
     DirectoryHelper::create($newPath, true);
     $image = '';
     $categoryOption = $categoryOptions['category'][$category];
     $categorySizes = $categoryOption['size'];
     if (empty($categorySizes)) {
         $categorySizes = $defaultCategoriesSize;
     }
     $saveOrigin = false;
     if (isset($categoryOptions['origin'])) {
         $saveOrigin = $categoryOptions['origin'];
     }
     if (isset($categoryOption['origin'])) {
         $saveOrigin = $categoryOption['origin'];
     }
     if ($saveOrigin) {
         list($width, $height) = getimagesize($path);
         $categorySizes['origin'] = ['width' => $width, 'height' => $height];
     }
     foreach ($categorySizes as $sizeName => $size) {
         $image = "{$imageName}-{$sizeName}." . FileHelper::getFileType($path);
         if (property_exists($this->imageCreator, 'dataProvider')) {
             $this->imageCreator->dataProvider = $this->owner->dataProvider;
         }
         $this->imageCreator->thumbnail($path, $size['width'], $size['height']);
         $this->imageCreator->save(implode(DIRECTORY_SEPARATOR, [$newPath, $image]));
     }
     return $imageName;
 }