Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
ImageResize Class Reference

Public Member Functions

 __construct (State $appState, MediaConfig $imageConfig, ProductImage $productImage, ImageFactory $imageFactory, ParamsBuilder $paramsBuilder, ViewConfig $viewConfig, AssertImageFactory $assertImageFactory, ThemeCustomizationConfig $themeCustomizationConfig, Collection $themeCollection, Filesystem $filesystem)
 
 resizeFromImageName (string $originalImageName)
 
 resizeFromThemes (array $themes=null)
 

Detailed Description

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 29 of file ImageResize.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( State  $appState,
MediaConfig  $imageConfig,
ProductImage  $productImage,
ImageFactory  $imageFactory,
ParamsBuilder  $paramsBuilder,
ViewConfig  $viewConfig,
AssertImageFactory  $assertImageFactory,
ThemeCustomizationConfig  $themeCustomizationConfig,
Collection  $themeCollection,
Filesystem  $filesystem 
)
Parameters
State$appState
MediaConfig$imageConfig
ProductImage$productImage
ImageFactory$imageFactory
ParamsBuilder$paramsBuilder
ViewConfig$viewConfig
AssertImageFactory$assertImageFactory
ThemeCustomizationConfig$themeCustomizationConfig
Collection$themeCollection
Filesystem$filesystem

Definition at line 100 of file ImageResize.php.

111  {
112  $this->appState = $appState;
113  $this->imageConfig = $imageConfig;
114  $this->productImage = $productImage;
115  $this->imageFactory = $imageFactory;
116  $this->paramsBuilder = $paramsBuilder;
117  $this->viewConfig = $viewConfig;
118  $this->assertImageFactory = $assertImageFactory;
119  $this->themeCustomizationConfig = $themeCustomizationConfig;
120  $this->themeCollection = $themeCollection;
121  $this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
122  $this->filesystem = $filesystem;
123  }
$filesystem

Member Function Documentation

◆ resizeFromImageName()

resizeFromImageName ( string  $originalImageName)

Create resized images of different sizes from an original image

Parameters
string$originalImageName
Exceptions
NotFoundException

Definition at line 130 of file ImageResize.php.

131  {
132  $originalImagePath = $this->mediaDirectory->getAbsolutePath(
133  $this->imageConfig->getMediaPath($originalImageName)
134  );
135  if (!$this->mediaDirectory->isFile($originalImagePath)) {
136  throw new NotFoundException(__('Cannot resize image "%1" - original image not found', $originalImagePath));
137  }
138  foreach ($this->getViewImages($this->getThemesInUse()) as $viewImage) {
139  $this->resize($viewImage, $originalImagePath, $originalImageName);
140  }
141  }
__()
Definition: __.php:13

◆ resizeFromThemes()

resizeFromThemes ( array  $themes = null)

Create resized images of different sizes from themes

Parameters
array | null$themes
Returns
\Generator
Exceptions
NotFoundException

Definition at line 149 of file ImageResize.php.

149  : \Generator
150  {
151  $count = $this->productImage->getCountAllProductImages();
152  if (!$count) {
153  throw new NotFoundException(__('Cannot resize images - product images not found'));
154  }
155 
156  $productImages = $this->productImage->getAllProductImages();
157  $viewImages = $this->getViewImages($themes ?? $this->getThemesInUse());
158 
159  foreach ($productImages as $image) {
160  $originalImageName = $image['filepath'];
161  $originalImagePath = $this->mediaDirectory->getAbsolutePath(
162  $this->imageConfig->getMediaPath($originalImageName)
163  );
164  foreach ($viewImages as $viewImage) {
165  $this->resize($viewImage, $originalImagePath, $originalImageName);
166  }
167  yield $originalImageName => $count;
168  }
169  }
$count
Definition: recent.phtml:13
__()
Definition: __.php:13

The documentation for this class was generated from the following file: