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

Public Member Functions

 __construct (\Magento\Framework\Image\Adapter\AdapterInterface $adapter, $fileName=null)
 
 open ()
 
 display ()
 
 save ($destination=null, $newFileName=null)
 
 rotate ($angle)
 
 crop ($top=0, $left=0, $right=0, $bottom=0)
 
 resize ($width, $height=null)
 
 keepAspectRatio ($value)
 
 keepFrame ($value)
 
 keepTransparency ($value)
 
 constrainOnly ($value)
 
 backgroundColor ($value)
 
 quality ($value)
 
 watermark ( $watermarkImage, $positionX=0, $positionY=0, $watermarkImageOpacity=30, $repeat=false)
 
 getMimeType ()
 
 getImageType ()
 
 process ()
 
 instruction ()
 
 setImageBackgroundColor ($color)
 
 setWatermarkPosition ($position)
 
 setWatermarkImageOpacity ($imageOpacity)
 
 setWatermarkWidth ($width)
 
 setWatermarkHeight ($height)
 
 getOriginalWidth ()
 
 getOriginalHeight ()
 
 createPngFromString ($text, $font='')
 

Protected Attributes

 $_adapter
 
 $_fileName
 

Detailed Description

Image handler library

Author
Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m

Definition at line 13 of file Image.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Image\Adapter\AdapterInterface  $adapter,
  $fileName = null 
)

Constructor

Parameters
Image\Adapter\AdapterInterface$adapter
string | null$fileName

Definition at line 31 of file Image.php.

32  {
33  $this->_adapter = $adapter;
34  $this->_fileName = $fileName;
35  if (isset($fileName)) {
36  $this->open();
37  }
38  }
$adapter
Definition: webapi_user.php:16
$fileName
Definition: translate.phtml:15

Member Function Documentation

◆ backgroundColor()

backgroundColor (   $value)

Get/set backgroundColor

Parameters
null | array$value
Returns
array|null

Definition at line 172 of file Image.php.

173  {
174  return $this->_adapter->backgroundColor($value);
175  }
$value
Definition: gender.phtml:16

◆ constrainOnly()

constrainOnly (   $value)

Get/set constrainOnly

Parameters
bool$value
Returns
bool

Definition at line 161 of file Image.php.

162  {
163  return $this->_adapter->constrainOnly($value);
164  }
$value
Definition: gender.phtml:16

◆ createPngFromString()

createPngFromString (   $text,
  $font = '' 
)

Create Image from string

Parameters
string$text
string$fontPath to font file
Returns
$this

Definition at line 343 of file Image.php.

344  {
345  $this->_adapter->createPngFromString($text, $font);
346  return $this;
347  }
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43

◆ crop()

crop (   $top = 0,
  $left = 0,
  $right = 0,
  $bottom = 0 
)

Crop an image.

Parameters
int$topDefault value is 0
int$leftDefault value is 0
int$rightDefault value is 0
int$bottomDefault value is 0 @access public
Returns
void

Definition at line 104 of file Image.php.

105  {
106  $this->_adapter->crop($top, $left, $right, $bottom);
107  }

◆ display()

display ( )

Display handled image in your browser

@access public

Returns
void

Definition at line 64 of file Image.php.

65  {
66  $this->_adapter->display();
67  }

◆ getImageType()

getImageType ( )

Get image type of handled image

@access public

Returns
int

Definition at line 230 of file Image.php.

231  {
232  return $this->_adapter->getImageType();
233  }

◆ getMimeType()

getMimeType ( )

Get mime type of handled image

@access public

Returns
string

Definition at line 219 of file Image.php.

220  {
221  return $this->_adapter->getMimeType();
222  }

◆ getOriginalHeight()

getOriginalHeight ( )

Retrieve original image height

Returns
int|null

Definition at line 331 of file Image.php.

332  {
333  return $this->_adapter->getOriginalHeight();
334  }

◆ getOriginalWidth()

getOriginalWidth ( )

Retrieve original image width

Returns
int|null

Definition at line 321 of file Image.php.

322  {
323  return $this->_adapter->getOriginalWidth();
324  }

◆ instruction()

instruction ( )

Instruction

@access public

Returns
void

Definition at line 251 of file Image.php.

252  {
253  }

◆ keepAspectRatio()

keepAspectRatio (   $value)

Get/set keepAspectRatio

Parameters
bool$value
Returns
bool

Definition at line 128 of file Image.php.

129  {
130  return $this->_adapter->keepAspectRatio($value);
131  }
$value
Definition: gender.phtml:16

◆ keepFrame()

keepFrame (   $value)

Get/set keepFrame

Parameters
bool$value
Returns
bool

Definition at line 139 of file Image.php.

140  {
141  return $this->_adapter->keepFrame($value);
142  }
$value
Definition: gender.phtml:16

◆ keepTransparency()

keepTransparency (   $value)

Get/set keepTransparency

Parameters
bool$value
Returns
bool

Definition at line 150 of file Image.php.

151  {
152  return $this->_adapter->keepTransparency($value);
153  }
$value
Definition: gender.phtml:16

◆ open()

open ( )

Opens an image and creates image handle

@access public

Returns
void
Exceptions

Definition at line 47 of file Image.php.

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  }

◆ process()

process ( )

Process

@access public

Returns
void

Definition at line 241 of file Image.php.

242  {
243  }

◆ quality()

quality (   $value)

Get/set quality, values in percentage from 0 to 100

Parameters
int$value
Returns
int

Definition at line 183 of file Image.php.

184  {
185  return $this->_adapter->quality($value);
186  }
$value
Definition: gender.phtml:16

◆ resize()

resize (   $width,
  $height = null 
)

Resize an image

Parameters
int$width
int$height@access public
Returns
void

Definition at line 117 of file Image.php.

118  {
119  $this->_adapter->resize($width, $height);
120  }

◆ rotate()

rotate (   $angle)

Rotate an image.

Parameters
int$angle@access public
Returns
void

Definition at line 89 of file Image.php.

90  {
91  $this->_adapter->rotate($angle);
92  }

◆ save()

save (   $destination = null,
  $newFileName = null 
)

Save handled image into file

Parameters
null | string$destinationDefault value is NULL
null | string$newFileNameDefault value is NULL @access public
Returns
void

Definition at line 77 of file Image.php.

78  {
79  $this->_adapter->save($destination, $newFileName);
80  }

◆ setImageBackgroundColor()

setImageBackgroundColor (   $color)

Set image background color

Parameters
int$color@access public
Returns
void

@noinspection PhpUndefinedFieldInspection

Definition at line 262 of file Image.php.

263  {
265  $this->_adapter->imageBackgroundColor = intval($color);
266  }

◆ setWatermarkHeight()

setWatermarkHeight (   $height)

Set watermark height

Parameters
int$height
Returns
$this

Definition at line 310 of file Image.php.

311  {
312  $this->_adapter->setWatermarkHeight($height);
313  return $this;
314  }

◆ setWatermarkImageOpacity()

setWatermarkImageOpacity (   $imageOpacity)

Set watermark image opacity

Parameters
int$imageOpacity
Returns
$this

Definition at line 286 of file Image.php.

287  {
288  $this->_adapter->setWatermarkImageOpacity($imageOpacity);
289  return $this;
290  }

◆ setWatermarkPosition()

setWatermarkPosition (   $position)

Set watermark position

Parameters
string$position
Returns
$this

Definition at line 274 of file Image.php.

275  {
276  $this->_adapter->setWatermarkPosition($position);
277  return $this;
278  }

◆ setWatermarkWidth()

setWatermarkWidth (   $width)

Set watermark width

Parameters
int$width
Returns
$this

Definition at line 298 of file Image.php.

299  {
300  $this->_adapter->setWatermarkWidth($width);
301  return $this;
302  }

◆ watermark()

watermark (   $watermarkImage,
  $positionX = 0,
  $positionY = 0,
  $watermarkImageOpacity = 30,
  $repeat = false 
)

Adds watermark to our image.

Parameters
string$watermarkImageAbsolute path to watermark image.
int$positionXWatermark X position.
int$positionYWatermark Y position.
int$watermarkImageOpacityWatermark image opacity.
bool$repeatEnable or disable watermark brick. @access public
Exceptions

Definition at line 200 of file Image.php.

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  }

Field Documentation

◆ $_adapter

$_adapter
protected

Definition at line 18 of file Image.php.

◆ $_fileName

$_fileName
protected

Definition at line 23 of file Image.php.


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