Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Image.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Framework;
7 
13 class Image
14 {
18  protected $_adapter;
19 
23  protected $_fileName;
24 
31  public function __construct(\Magento\Framework\Image\Adapter\AdapterInterface $adapter, $fileName = null)
32  {
33  $this->_adapter = $adapter;
34  $this->_fileName = $fileName;
35  if (isset($fileName)) {
36  $this->open();
37  }
38  }
39 
47  public function open()
48  {
49  $this->_adapter->checkDependencies();
50 
51  if (!file_exists($this->_fileName)) {
52  throw new \Exception("File '{$this->_fileName}' does not exist.");
53  }
54 
55  $this->_adapter->open($this->_fileName);
56  }
57 
64  public function display()
65  {
66  $this->_adapter->display();
67  }
68 
77  public function save($destination = null, $newFileName = null)
78  {
79  $this->_adapter->save($destination, $newFileName);
80  }
81 
89  public function rotate($angle)
90  {
91  $this->_adapter->rotate($angle);
92  }
93 
104  public function crop($top = 0, $left = 0, $right = 0, $bottom = 0)
105  {
106  $this->_adapter->crop($top, $left, $right, $bottom);
107  }
108 
117  public function resize($width, $height = null)
118  {
119  $this->_adapter->resize($width, $height);
120  }
121 
128  public function keepAspectRatio($value)
129  {
130  return $this->_adapter->keepAspectRatio($value);
131  }
132 
139  public function keepFrame($value)
140  {
141  return $this->_adapter->keepFrame($value);
142  }
143 
150  public function keepTransparency($value)
151  {
152  return $this->_adapter->keepTransparency($value);
153  }
154 
161  public function constrainOnly($value)
162  {
163  return $this->_adapter->constrainOnly($value);
164  }
165 
172  public function backgroundColor($value)
173  {
174  return $this->_adapter->backgroundColor($value);
175  }
176 
183  public function quality($value)
184  {
185  return $this->_adapter->quality($value);
186  }
187 
200  public function watermark(
201  $watermarkImage,
202  $positionX = 0,
203  $positionY = 0,
204  $watermarkImageOpacity = 30,
205  $repeat = false
206  ) {
207  if (!file_exists($watermarkImage)) {
208  throw new \Exception("Required file '{$watermarkImage}' does not exists.");
209  }
210  $this->_adapter->watermark($watermarkImage, $positionX, $positionY, $watermarkImageOpacity, $repeat);
211  }
212 
219  public function getMimeType()
220  {
221  return $this->_adapter->getMimeType();
222  }
223 
230  public function getImageType()
231  {
232  return $this->_adapter->getImageType();
233  }
234 
241  public function process()
242  {
243  }
244 
251  public function instruction()
252  {
253  }
254 
262  public function setImageBackgroundColor($color)
263  {
265  $this->_adapter->imageBackgroundColor = intval($color);
266  }
267 
274  public function setWatermarkPosition($position)
275  {
276  $this->_adapter->setWatermarkPosition($position);
277  return $this;
278  }
279 
286  public function setWatermarkImageOpacity($imageOpacity)
287  {
288  $this->_adapter->setWatermarkImageOpacity($imageOpacity);
289  return $this;
290  }
291 
298  public function setWatermarkWidth($width)
299  {
300  $this->_adapter->setWatermarkWidth($width);
301  return $this;
302  }
303 
310  public function setWatermarkHeight($height)
311  {
312  $this->_adapter->setWatermarkHeight($height);
313  return $this;
314  }
315 
321  public function getOriginalWidth()
322  {
323  return $this->_adapter->getOriginalWidth();
324  }
325 
331  public function getOriginalHeight()
332  {
333  return $this->_adapter->getOriginalHeight();
334  }
335 
343  public function createPngFromString($text, $font = '')
344  {
345  $this->_adapter->createPngFromString($text, $font);
346  return $this;
347  }
348 }
backgroundColor($value)
Definition: Image.php:172
setImageBackgroundColor($color)
Definition: Image.php:262
setWatermarkImageOpacity($imageOpacity)
Definition: Image.php:286
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43
setWatermarkWidth($width)
Definition: Image.php:298
keepTransparency($value)
Definition: Image.php:150
setWatermarkPosition($position)
Definition: Image.php:274
$adapter
Definition: webapi_user.php:16
resize($width, $height=null)
Definition: Image.php:117
$fileName
Definition: translate.phtml:15
setWatermarkHeight($height)
Definition: Image.php:310
$value
Definition: gender.phtml:16
__construct(\Magento\Framework\Image\Adapter\AdapterInterface $adapter, $fileName=null)
Definition: Image.php:31
keepAspectRatio($value)
Definition: Image.php:128
watermark( $watermarkImage, $positionX=0, $positionY=0, $watermarkImageOpacity=30, $repeat=false)
Definition: Image.php:200
save($destination=null, $newFileName=null)
Definition: Image.php:77
createPngFromString($text, $font='')
Definition: Image.php:343
crop($top=0, $left=0, $right=0, $bottom=0)
Definition: Image.php:104