179 abstract public function save($destination =
null, $newName =
null);
186 abstract public function getImage();
195 abstract public function resize($width =
null, $height =
null);
203 abstract public function rotate($angle);
214 abstract public function crop($top = 0, $left = 0, $right = 0, $bottom = 0);
226 abstract public function watermark($imagePath, $positionX = 0, $positionY = 0, $opacity = 30, $tile =
false);
271 \Psr\Log\LoggerInterface
$logger,
286 if ($this->_fileMimeType) {
289 $this->_fileMimeType = image_type_to_mime_type($this->
getImageType());
301 if ($this->_fileType) {
305 list($this->_imageSrcWidth, $this->_imageSrcHeight, $this->_fileType) =
getimagesize($this->_fileName);
342 $this->_watermarkPosition = $position;
364 $this->_watermarkImageOpacity = $imageOpacity;
386 $this->_watermarkWidth = $width;
408 $this->_watermarkHeight = $height;
431 $this->_keepAspectRatio = (bool)
$value;
445 $this->_keepFrame = (bool)
$value;
459 $this->_keepTransparency = (bool)
$value;
473 $this->_constrainOnly = (bool)
$value;
487 $this->_quality = (int)
$value;
504 foreach (
$value as $color) {
505 if (!is_integer($color) || $color < 0 || $color > 255) {
510 $this->_backgroundColor =
$value;
521 $pathinfo = pathinfo($this->_fileName);
523 $this->_fileSrcPath = $pathinfo[
'dirname'];
524 $this->_fileSrcName = $pathinfo[
'basename'];
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]
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];
619 if ($frameWidth !==
null && $frameWidth <= 0 ||
620 $frameHeight !==
null && $frameHeight <= 0 ||
621 empty($frameWidth) && empty($frameHeight)
623 throw new \Exception(
'Invalid image dimensions.');
634 return !empty($this->_imageSrcWidth) && !empty($this->_imageSrcHeight);
655 return [
'gif',
'jpeg',
'jpg',
'png'];
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.');
704 return !empty($this->_fileName);
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);
createPngFromString($text, $font='')
elseif(isset( $params[ 'redirect_parent']))
_adaptResizeValues($frameWidth, $frameHeight)
save($destination=null, $newName=null)
watermark($imagePath, $positionX=0, $positionY=0, $opacity=30, $tile=false)
setWatermarkHeight($height)
const POSITION_BOTTOM_RIGHT
getWatermarkImageOpacity()
keepAspectRatio($value=null)
resize($width=null, $height=null)
constrainOnly($value=null)
_checkDimensions($frameWidth, $frameHeight)
backgroundColor($value=null)
validateUploadFile($filePath)
const POSITION_BOTTOM_LEFT
keepTransparency($value=null)
setWatermarkPosition($position)
setWatermarkImageOpacity($imageOpacity)
foreach( $_productCollection as $_product)() ?>" class $info
__construct(\Magento\Framework\Filesystem $filesystem, \Psr\Log\LoggerInterface $logger, array $data=[])
_prepareDestination($destination=null, $newName=null)
_getImageOptions($filePath)
setWatermarkWidth($width)
_checkAspectRatio($frameWidth, $frameHeight)
crop($top=0, $left=0, $right=0, $bottom=0)