Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
MediaGallery Class Reference
Inheritance diagram for MediaGallery:

Public Member Functions

 __construct (array $params, $data=[])
 

Protected Member Functions

 createTestImage ($filename)
 
 getFullPath ($filename)
 

Protected Attributes

 $mediaPathTmp = '/pub/media/tmp/catalog/product'
 

Detailed Description

Media Gallery data source.

Data keys:

Definition at line 18 of file MediaGallery.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $params,
  $data = [] 
)

@constructor

Parameters
array$params
array$data@SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 33 of file MediaGallery.php.

34  {
35  if (isset($data['images']) && is_array($data['images']) && count($data['images'])) {
36  foreach ($data['images'] as $media) {
37  if (isset($media['file'])) {
38  $this->createTestImage($media['file']);
39  }
40  }
41  }
42  $this->data = $data;
43  }

Member Function Documentation

◆ createTestImage()

createTestImage (   $filename)
protected

Create test image.

Parameters
string$filename
Returns
void

Definition at line 51 of file MediaGallery.php.

52  {
53  $filename = $this->getFullPath($filename);
54  if (!file_exists($filename)) {
55  // Create an image with the specified dimensions
56  $image = imageCreate(300, 200);
57 
58  // Create a color (this first call to imageColorAllocate
59  // also automatically sets the image background color)
60  $colorYellow = imageColorAllocate($image, 255, 255, 0);
61 
62  // Draw a rectangle
63  imageFilledRectangle($image, 50, 50, 250, 150, $colorYellow);
64 
65  $directory = dirname($filename);
66  if (!file_exists($directory)) {
67  mkdir($directory, 0777, true);
68  }
69  imageJpeg($image, $filename);
70 
71  // Release memory
72  imageDestroy($image);
73  }
74  }
mkdir($pathname, $mode=0777, $recursive=false, $context=null)
Definition: ioMock.php:25

◆ getFullPath()

getFullPath (   $filename)
protected

Gets full path based on filename.

Parameters
string$filename
Returns
string

Definition at line 82 of file MediaGallery.php.

83  {
84  return BP . $this->mediaPathTmp . $filename;
85  }
const BP
Definition: autoload.php:14

Field Documentation

◆ $mediaPathTmp

$mediaPathTmp = '/pub/media/tmp/catalog/product'
protected

Definition at line 25 of file MediaGallery.php.


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