|
| open ($fileName) |
|
| save ($destination=null, $newName=null) |
|
| getImage () |
|
| resize ($width=null, $height=null) |
|
| rotate ($angle) |
|
| crop ($top=0, $left=0, $right=0, $bottom=0) |
|
| watermark ($imagePath, $positionX=0, $positionY=0, $opacity=30, $tile=false) |
|
| checkDependencies () |
|
| createPngFromString ($text, $font='') |
|
| refreshImageDimensions () |
|
| getColorAt ($x, $y) |
|
| __construct (\Magento\Framework\Filesystem $filesystem, \Psr\Log\LoggerInterface $logger, array $data=[]) |
|
| getMimeType () |
|
| getImageType () |
|
| getOriginalWidth () |
|
| getOriginalHeight () |
|
| setWatermarkPosition ($position) |
|
| getWatermarkPosition () |
|
| setWatermarkImageOpacity ($imageOpacity) |
|
| getWatermarkImageOpacity () |
|
| setWatermarkWidth ($width) |
|
| getWatermarkWidth () |
|
| setWatermarkHeight ($height) |
|
| getWatermarkHeight () |
|
| keepAspectRatio ($value=null) |
|
| keepFrame ($value=null) |
|
| keepTransparency ($value=null) |
|
| constrainOnly ($value=null) |
|
| quality ($value=null) |
|
| backgroundColor ($value=null) |
|
| getSupportedFormats () |
|
| validateUploadFile ($filePath) |
|
Definition at line 15 of file AbstractAdapter.php.
◆ __construct()
Initialize default values
- Parameters
-
\Magento\Framework\Filesystem | $filesystem | |
\Psr\Log\LoggerInterface | $logger | |
array | $data | @SuppressWarnings(PHPMD.UnusedFormalParameter) |
Definition at line 269 of file AbstractAdapter.php.
◆ _adaptResizeValues()
_adaptResizeValues |
( |
|
$frameWidth, |
|
|
|
$frameHeight |
|
) |
| |
|
protected |
Adapt resize values based on image configuration
- Parameters
-
int | $frameWidth | |
int | $frameHeight | |
- Returns
- array
- Exceptions
-
Definition at line 535 of file AbstractAdapter.php.
541 if (
null === $frameWidth) {
542 $frameWidth = round($frameHeight * ($this->_imageSrcWidth / $this->_imageSrcHeight));
543 }
elseif (
null === $frameHeight) {
544 $frameHeight = round($frameWidth * ($this->_imageSrcHeight / $this->_imageSrcWidth));
547 if (
null === $frameWidth) {
548 $frameWidth = $frameHeight;
549 }
elseif (
null === $frameHeight) {
550 $frameHeight = $frameWidth;
557 list($dstWidth, $dstHeight) = $this->
_checkAspectRatio($frameWidth, $frameHeight);
561 $dstY = round(($frameHeight - $dstHeight) / 2);
562 $dstX = round(($frameWidth - $dstWidth) / 2);
565 if (!$this->_keepFrame) {
566 $frameWidth = $dstWidth;
567 $frameHeight = $dstHeight;
573 'src' => [
'x' => $srcX,
'y' => $srcY],
574 'dst' => [
'x' => $dstX,
'y' => $dstY,
'width' => $dstWidth,
'height' => $dstHeight],
576 'frame' => [
'width' => $frameWidth,
'height' => $frameHeight]
elseif(isset( $params[ 'redirect_parent']))
_checkDimensions($frameWidth, $frameHeight)
_checkAspectRatio($frameWidth, $frameHeight)
◆ _canProcess()
Checks is adapter can work with image
- Returns
- bool
Definition at line 702 of file AbstractAdapter.php.
704 return !empty($this->_fileName);
◆ _checkAspectRatio()
_checkAspectRatio |
( |
|
$frameWidth, |
|
|
|
$frameHeight |
|
) |
| |
|
protected |
Check aspect ratio
- Parameters
-
int | $frameWidth | |
int | $frameHeight | |
- Returns
- int[]
Definition at line 587 of file AbstractAdapter.php.
589 $dstWidth = $frameWidth;
590 $dstHeight = $frameHeight;
593 if ($this->_constrainOnly) {
594 if ($frameWidth >= $this->_imageSrcWidth && $frameHeight >= $this->_imageSrcHeight) {
600 if ($this->_imageSrcWidth / $this->_imageSrcHeight >= $frameWidth / $frameHeight) {
601 $dstHeight = round($dstWidth / $this->_imageSrcWidth * $this->_imageSrcHeight);
603 $dstWidth = round($dstHeight / $this->_imageSrcHeight * $this->_imageSrcWidth);
606 return [$dstWidth, $dstHeight];
◆ _checkDimensions()
_checkDimensions |
( |
|
$frameWidth, |
|
|
|
$frameHeight |
|
) |
| |
|
protected |
Check Frame dimensions and throw exception if they are not valid
- Parameters
-
int | $frameWidth | |
int | $frameHeight | |
- Returns
- void
- Exceptions
-
Definition at line 617 of file AbstractAdapter.php.
619 if ($frameWidth !==
null && $frameWidth <= 0 ||
620 $frameHeight !==
null && $frameHeight <= 0 ||
621 empty($frameWidth) && empty($frameHeight)
623 throw new \Exception(
'Invalid image dimensions.');
◆ _checkSrcDimensions()
Return false if source width or height is empty
- Returns
- bool
Definition at line 632 of file AbstractAdapter.php.
634 return !empty($this->_imageSrcWidth) && !empty($this->_imageSrcHeight);
◆ _getFileAttributes()
Assign file dirname and basename to object properties
- Returns
- void
Definition at line 519 of file AbstractAdapter.php.
521 $pathinfo = pathinfo($this->_fileName);
523 $this->_fileSrcPath = $pathinfo[
'dirname'];
524 $this->_fileSrcName = $pathinfo[
'basename'];
◆ _getImageOptions()
_getImageOptions |
( |
|
$filePath | ) |
|
|
protected |
Return information about image using getimagesize function
- Parameters
-
- Returns
- array
Definition at line 643 of file AbstractAdapter.php.
◆ _prepareDestination()
_prepareDestination |
( |
|
$destination = null , |
|
|
|
$newName = null |
|
) |
| |
|
protected |
Create destination folder if not exists and return full file path
- Parameters
-
string | $destination | |
string | $newName | |
- Returns
- string
- Exceptions
-
Definition at line 666 of file AbstractAdapter.php.
668 if (empty($destination)) {
671 if (empty($newName)) {
672 $info = pathinfo($destination);
673 $newName =
$info[
'basename'];
674 $destination =
$info[
'dirname'];
678 if (empty($newName)) {
681 $newFileName = $newName;
683 $fileName = $destination .
'/' . $newFileName;
687 $this->directoryWrite->create($this->directoryWrite->getRelativePath($destination));
688 }
catch (\
Magento\Framework\Exception\FileSystemException $e) {
689 $this->logger->critical($e);
690 throw new \Exception(
'Unable to write file into directory ' . $destination .
'. Access forbidden.');
foreach( $_productCollection as $_product)() ?>" class $info
◆ backgroundColor()
backgroundColor |
( |
|
$value = null | ) |
|
Get/set keepBackgroundColor
- Parameters
-
- Returns
- array|void
Definition at line 498 of file AbstractAdapter.php.
504 foreach (
$value as $color) {
505 if (!is_integer($color) || $color < 0 || $color > 255) {
510 $this->_backgroundColor =
$value;
◆ checkDependencies()
Checks required dependencies
- Returns
- void
- Exceptions
-
Implements AdapterInterface.
◆ constrainOnly()
constrainOnly |
( |
|
$value = null | ) |
|
◆ createPngFromString()
createPngFromString |
( |
|
$text, |
|
|
|
$font = '' |
|
) |
| |
|
abstract |
◆ crop()
crop |
( |
|
$top = 0 , |
|
|
|
$left = 0 , |
|
|
|
$right = 0 , |
|
|
|
$bottom = 0 |
|
) |
| |
|
abstract |
Crop image
- Parameters
-
int | $top | |
int | $left | |
int | $right | |
int | $bottom | |
- Returns
- bool
Implements AdapterInterface.
◆ getColorAt()
Returns rgba array of the specified pixel
- Parameters
-
- Returns
- array
Implements AdapterInterface.
◆ getImage()
Render image and return its binary contents
- Returns
- string
Implements AdapterInterface.
◆ getImageType()
Assign image width, height, fileType to object properties using getimagesize function
- Returns
- int|null
Definition at line 299 of file AbstractAdapter.php.
301 if ($this->_fileType) {
305 list($this->_imageSrcWidth, $this->_imageSrcHeight, $this->_fileType) =
getimagesize($this->_fileName);
◆ getMimeType()
Assign image width, height, fileMimeType to object properties
- Returns
- string|null
Definition at line 284 of file AbstractAdapter.php.
286 if ($this->_fileMimeType) {
289 $this->_fileMimeType = image_type_to_mime_type($this->
getImageType());
◆ getOriginalHeight()
◆ getOriginalWidth()
◆ getSupportedFormats()
Return supported image formats
- Returns
- string[]
Definition at line 653 of file AbstractAdapter.php.
655 return [
'gif',
'jpeg',
'jpg',
'png'];
◆ getWatermarkHeight()
◆ getWatermarkImageOpacity()
getWatermarkImageOpacity |
( |
| ) |
|
◆ getWatermarkPosition()
◆ getWatermarkWidth()
◆ keepAspectRatio()
keepAspectRatio |
( |
|
$value = null | ) |
|
Get/set keepAspectRatio
- Parameters
-
- Returns
- bool|\Magento\Framework\Image\Adapter\AbstractAdapter
Definition at line 428 of file AbstractAdapter.php.
431 $this->_keepAspectRatio = (bool)
$value;
◆ keepFrame()
keepFrame |
( |
|
$value = null | ) |
|
◆ keepTransparency()
keepTransparency |
( |
|
$value = null | ) |
|
Get/set keepTransparency
- Parameters
-
- Returns
- bool
Definition at line 456 of file AbstractAdapter.php.
459 $this->_keepTransparency = (bool)
$value;
◆ open()
◆ quality()
Get/set quality, values in percentage from 0 to 100
- Parameters
-
- Returns
- int
Definition at line 484 of file AbstractAdapter.php.
487 $this->_quality = (int)
$value;
◆ refreshImageDimensions()
refreshImageDimensions |
( |
| ) |
|
|
abstract |
◆ resize()
resize |
( |
|
$width = null , |
|
|
|
$height = null |
|
) |
| |
|
abstract |
Change the image size
- Parameters
-
null | int | $width | |
null | int | $height | |
- Returns
- void
Implements AdapterInterface.
◆ rotate()
Rotate image on specific angle
- Parameters
-
- Returns
- void
Implements AdapterInterface.
◆ save()
save |
( |
|
$destination = null , |
|
|
|
$newName = null |
|
) |
| |
|
abstract |
Save image to specific path. If some folders of path does not exist they will be created
- Parameters
-
null | string | $destination | |
null | string | $newName | |
- Returns
- void
- Exceptions
-
Implements AdapterInterface.
◆ setWatermarkHeight()
setWatermarkHeight |
( |
|
$height | ) |
|
Set watermark height
- Parameters
-
- Returns
- $this
Definition at line 406 of file AbstractAdapter.php.
408 $this->_watermarkHeight = $height;
◆ setWatermarkImageOpacity()
setWatermarkImageOpacity |
( |
|
$imageOpacity | ) |
|
Set watermark opacity
- Parameters
-
- Returns
- $this
Definition at line 362 of file AbstractAdapter.php.
364 $this->_watermarkImageOpacity = $imageOpacity;
◆ setWatermarkPosition()
setWatermarkPosition |
( |
|
$position | ) |
|
Set watermark position
- Parameters
-
- Returns
- $this
Definition at line 340 of file AbstractAdapter.php.
342 $this->_watermarkPosition = $position;
◆ setWatermarkWidth()
setWatermarkWidth |
( |
|
$width | ) |
|
Set watermark width
- Parameters
-
- Returns
- $this
Definition at line 384 of file AbstractAdapter.php.
386 $this->_watermarkWidth = $width;
◆ validateUploadFile()
validateUploadFile |
( |
|
$filePath | ) |
|
Check - is this file an image
- Parameters
-
- Returns
- bool
- Exceptions
-
Definition at line 714 of file AbstractAdapter.php.
716 if (!file_exists($filePath)) {
717 throw new \InvalidArgumentException(
"File '{$filePath}' does not exists.");
720 throw new \InvalidArgumentException(
'Disallowed file type.');
723 $this->
open($filePath);
◆ watermark()
watermark |
( |
|
$imagePath, |
|
|
|
$positionX = 0 , |
|
|
|
$positionY = 0 , |
|
|
|
$opacity = 30 , |
|
|
|
$tile = false |
|
) |
| |
|
abstract |
Add watermark to image
- Parameters
-
string | $imagePath | |
int | $positionX | |
int | $positionY | |
int | $opacity | |
bool | $tile | |
- Returns
- void
Implements AdapterInterface.
◆ $_backgroundColor
◆ $_constrainOnly
◆ $_fileMimeType
◆ $_fileName
◆ $_fileSrcName
◆ $_fileSrcPath
◆ $_filesystem
◆ $_fileType
◆ $_fontSize
$_fontSize = self::DEFAULT_FONT_SIZE |
|
protected |
◆ $_imageHandler
◆ $_imageSrcHeight
◆ $_imageSrcWidth
◆ $_keepAspectRatio
◆ $_keepFrame
◆ $_keepTransparency
◆ $_quality
◆ $_requiredExtensions
◆ $_watermarkHeight
◆ $_watermarkImageOpacity
◆ $_watermarkPosition
◆ $_watermarkWidth
◆ $directoryWrite
◆ $imageBackgroundColor
$imageBackgroundColor = 0 |
◆ $logger
◆ DEFAULT_FONT_SIZE
const DEFAULT_FONT_SIZE = 15 |
◆ POSITION_BOTTOM_LEFT
const POSITION_BOTTOM_LEFT = 'bottom-left' |
◆ POSITION_BOTTOM_RIGHT
const POSITION_BOTTOM_RIGHT = 'bottom-right' |
◆ POSITION_CENTER
const POSITION_CENTER = 'center' |
◆ POSITION_STRETCH
const POSITION_STRETCH = 'stretch' |
◆ POSITION_TILE
const POSITION_TILE = 'tile' |
◆ POSITION_TOP_LEFT
const POSITION_TOP_LEFT = 'top-left' |
◆ POSITION_TOP_RIGHT
const POSITION_TOP_RIGHT = 'top-right' |
The documentation for this class was generated from the following file: