1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2014 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
8
8
namespace Magento \Framework \Image \Adapter ;
9
9
10
10
use 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 ;
11
15
12
16
/**
13
17
* Image abstract adapter
@@ -151,17 +155,17 @@ abstract class AbstractAdapter implements AdapterInterface
151
155
/**
152
156
* Filesystem instance
153
157
*
154
- * @var \Magento\Framework\ Filesystem
158
+ * @var Filesystem
155
159
*/
156
160
protected $ _filesystem ;
157
161
158
162
/**
159
- * @var \Magento\Framework\Filesystem\Directory\ Write
163
+ * @var Write
160
164
*/
161
165
protected $ directoryWrite ;
162
166
163
167
/**
164
- * @var \Psr\Log\ LoggerInterface
168
+ * @var LoggerInterface
165
169
*/
166
170
protected $ logger ;
167
171
@@ -268,14 +272,14 @@ abstract public function getColorAt($x, $y);
268
272
/**
269
273
* Initialize default values
270
274
*
271
- * @param \Magento\Framework\ Filesystem $filesystem
272
- * @param \Psr\Log\ LoggerInterface $logger
275
+ * @param Filesystem $filesystem
276
+ * @param LoggerInterface $logger
273
277
* @param array $data
274
278
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
275
279
*/
276
280
public function __construct (
277
- \ Magento \ Framework \ Filesystem $ filesystem ,
278
- \ Psr \ Log \ LoggerInterface $ logger ,
281
+ Filesystem $ filesystem ,
282
+ LoggerInterface $ logger ,
279
283
array $ data = []
280
284
) {
281
285
$ this ->_filesystem = $ filesystem ;
@@ -558,6 +562,9 @@ protected function _adaptResizeValues($frameWidth, $frameHeight)
558
562
}
559
563
}
560
564
565
+ $ frameWidth = (float )$ frameWidth ;
566
+ $ frameHeight = (float )$ frameHeight ;
567
+
561
568
// define coordinates of image inside new frame
562
569
$ srcX = 0 ;
563
570
$ srcY = 0 ;
@@ -578,17 +585,17 @@ protected function _adaptResizeValues($frameWidth, $frameHeight)
578
585
579
586
return [
580
587
'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) ],
582
589
// size for new image
583
- 'frame ' => ['width ' => $ frameWidth , 'height ' => $ frameHeight ]
590
+ 'frame ' => ['width ' => round ( $ frameWidth) , 'height ' => round ( $ frameHeight) ]
584
591
];
585
592
}
586
593
587
594
/**
588
595
* Check aspect ratio
589
596
*
590
- * @param int $frameWidth
591
- * @param int $frameHeight
597
+ * @param int|float $frameWidth
598
+ * @param int|float $frameHeight
592
599
* @return int[]
593
600
*/
594
601
protected function _checkAspectRatio ($ frameWidth , $ frameHeight )
@@ -605,10 +612,7 @@ protected function _checkAspectRatio($frameWidth, $frameHeight)
605
612
}
606
613
// keep aspect ratio
607
614
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 ));
612
616
} else {
613
617
$ dstWidth = round ($ dstHeight / $ this ->_imageSrcHeight * $ this ->_imageSrcWidth );
614
618
}
@@ -694,7 +698,7 @@ protected function _prepareDestination($destination = null, $newName = null)
694
698
if (!is_writable ($ destination )) {
695
699
try {
696
700
$ this ->directoryWrite ->create ($ this ->directoryWrite ->getRelativePath ($ destination ));
697
- } catch (\ Magento \ Framework \ Exception \ FileSystemException $ e ) {
701
+ } catch (FileSystemException $ e ) {
698
702
$ this ->logger ->critical ($ e );
699
703
//phpcs:ignore Magento2.Exceptions.DirectThrow
700
704
throw new \DomainException (
0 commit comments