public function thumbnail($pathToImage, $width, $height) { try { $this->openImage = $this->imagine->open(FileHelper::normalizePath($pathToImage))->thumbnail(new \Imagine\Image\Box($width, $height)); } catch (\Exception $ex) { \Codeception\Util\Debug::debug($ex->getMessage()); } }
/** * Get the image in a $type size. * @param string $category image category * @param string $type image type. Example 'thumb' * @param string $name image name * @return bool|string return name or false if image not exist */ public function get($category, $type, $name) { /* Get the path to the folder with the images. */ $directory = \Yii::getAlias($this->owner->imagesPath); $imagePath = implode(DIRECTORY_SEPARATOR, [$directory, $category]); $images = glob($imagePath . DIRECTORY_SEPARATOR . "{$name}-{$type}.*"); if ($images === false) { return false; } /* Get the first matched file. */ $image = $images[0]; return FileHelper::normalizePath($image); }
public function testImagableGet() { $nameClass = new CRC32Name(); $imagable = \Yii::createObject(['class' => 'bl\\imagable\\Imagable', 'imagesPath' => '@tests/_data/images', 'nameClass' => $nameClass->className(), 'imageClass' => 'bl\\imagable\\instances\\CreateImageImagine']); //image name $name = 'testImage'; $name = $nameClass->getName($name); $path =& $this->path; $pathToGalery = implode(DIRECTORY_SEPARATOR, [$path, 'galery']); $pathToGalery = FileHelper::normalizePath(\Yii::getAlias($pathToGalery)); //return full path. Example: /var/www/site/images/galery/5cc22de8-small.jpg $this->assertEquals($imagable->get('galery', 'small', $name), $pathToGalery . \DIRECTORY_SEPARATOR . $name . '-small.jpg'); //return full path. Example: /var/www/site/images/galery/5cc22de8-small.jpg $this->assertEquals($imagable->getSmall('galery', $name), $pathToGalery . \DIRECTORY_SEPARATOR . $name . '-small.jpg'); //return full path. Example: /var/www/site/images/galery/5cc22de8-big.jpg $stream = null; $this->assertEquals($imagable->getBig('galery', $name), $pathToGalery . \DIRECTORY_SEPARATOR . $name . '-big.jpg'); // \Codeception\Util\Debug::debug($imagable->getOriginal('galery', $name, $stream)); //return full path. Example: /var/www/site/images/galery/5cc22de8-original.jpg $this->assertEquals($imagable->getOriginal('galery', $name), $pathToGalery . \DIRECTORY_SEPARATOR . $name . '-origin.jpg'); //return full path. Example: /var/www/site/images/galery/5cc22de8-thumb.jpg $this->assertEquals($imagable->getThumb('galery', $name), $pathToGalery . \DIRECTORY_SEPARATOR . $name . '-thumb.jpg'); }
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; }
public function getSmall() { $image = $this->getImage('small'); return '/images/shop-product/' . FileHelper::getFullName($image); }