11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2014 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
88namespace Magento \Framework \Image \Adapter ;
99
1010use Magento \Framework \App \Filesystem \DirectoryList ;
11+ use Magento \Framework \Exception \FileSystemException ;
12+ use Magento \Framework \Filesystem ;
13+ use Magento \Framework \Filesystem \Directory \Write ;
14+ use Psr \Log \LoggerInterface ;
1115
1216/**
1317 * Image abstract adapter
@@ -151,17 +155,17 @@ abstract class AbstractAdapter implements AdapterInterface
151155 /**
152156 * Filesystem instance
153157 *
154- * @var \Magento\Framework\ Filesystem
158+ * @var Filesystem
155159 */
156160 protected $ _filesystem ;
157161
158162 /**
159- * @var \Magento\Framework\Filesystem\Directory\ Write
163+ * @var Write
160164 */
161165 protected $ directoryWrite ;
162166
163167 /**
164- * @var \Psr\Log\ LoggerInterface
168+ * @var LoggerInterface
165169 */
166170 protected $ logger ;
167171
@@ -268,14 +272,14 @@ abstract public function getColorAt($x, $y);
268272 /**
269273 * Initialize default values
270274 *
271- * @param \Magento\Framework\ Filesystem $filesystem
272- * @param \Psr\Log\ LoggerInterface $logger
275+ * @param Filesystem $filesystem
276+ * @param LoggerInterface $logger
273277 * @param array $data
274278 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
275279 */
276280 public function __construct (
277- \ Magento \ Framework \ Filesystem $ filesystem ,
278- \ Psr \ Log \ LoggerInterface $ logger ,
281+ Filesystem $ filesystem ,
282+ LoggerInterface $ logger ,
279283 array $ data = []
280284 ) {
281285 $ this ->_filesystem = $ filesystem ;
@@ -558,6 +562,9 @@ protected function _adaptResizeValues($frameWidth, $frameHeight)
558562 }
559563 }
560564
565+ $ frameWidth = (float )$ frameWidth ;
566+ $ frameHeight = (float )$ frameHeight ;
567+
561568 // define coordinates of image inside new frame
562569 $ srcX = 0 ;
563570 $ srcY = 0 ;
@@ -578,17 +585,17 @@ protected function _adaptResizeValues($frameWidth, $frameHeight)
578585
579586 return [
580587 'src ' => ['x ' => $ srcX , 'y ' => $ srcY ],
581- 'dst ' => ['x ' => $ dstX , 'y ' => $ dstY , 'width ' => $ dstWidth , 'height ' => $ dstHeight ],
588+ 'dst ' => ['x ' => $ dstX , 'y ' => $ dstY , 'width ' => round ( $ dstWidth) , 'height ' => round ( $ dstHeight) ],
582589 // size for new image
583- 'frame ' => ['width ' => $ frameWidth , 'height ' => $ frameHeight ]
590+ 'frame ' => ['width ' => round ( $ frameWidth) , 'height ' => round ( $ frameHeight) ]
584591 ];
585592 }
586593
587594 /**
588595 * Check aspect ratio
589596 *
590- * @param int $frameWidth
591- * @param int $frameHeight
597+ * @param int|float $frameWidth
598+ * @param int|float $frameHeight
592599 * @return int[]
593600 */
594601 protected function _checkAspectRatio ($ frameWidth , $ frameHeight )
@@ -605,10 +612,7 @@ protected function _checkAspectRatio($frameWidth, $frameHeight)
605612 }
606613 // keep aspect ratio
607614 if ($ this ->_imageSrcWidth / $ this ->_imageSrcHeight >= $ frameWidth / $ frameHeight ) {
608- $ dstHeight = max (
609- 1 ,
610- round ($ dstWidth / $ this ->_imageSrcWidth * $ this ->_imageSrcHeight )
611- );
615+ $ dstHeight = max (1 , round ($ dstWidth / $ this ->_imageSrcWidth * $ this ->_imageSrcHeight ));
612616 } else {
613617 $ dstWidth = round ($ dstHeight / $ this ->_imageSrcHeight * $ this ->_imageSrcWidth );
614618 }
@@ -694,7 +698,7 @@ protected function _prepareDestination($destination = null, $newName = null)
694698 if (!is_writable ($ destination )) {
695699 try {
696700 $ this ->directoryWrite ->create ($ this ->directoryWrite ->getRelativePath ($ destination ));
697- } catch (\ Magento \ Framework \ Exception \ FileSystemException $ e ) {
701+ } catch (FileSystemException $ e ) {
698702 $ this ->logger ->critical ($ e );
699703 //phpcs:ignore Magento2.Exceptions.DirectThrow
700704 throw new \DomainException (
0 commit comments