File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed
app/code/Magento/MediaStorage/Model/File/Validator
lib/internal/Magento/Framework/Image/Adapter Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change 9
9
10
10
use Magento \Framework \File \Mime ;
11
11
use Magento \Framework \Filesystem \Driver \File ;
12
+ use Magento \Framework \Image \Factory ;
12
13
13
14
/**
14
15
* Image validator
@@ -33,20 +34,28 @@ class Image extends \Zend_Validate_Abstract
33
34
*/
34
35
private $ fileMime ;
35
36
37
+ /**
38
+ * @var Factory
39
+ */
40
+ private $ imageFactory ;
41
+
36
42
/**
37
43
* @var File
38
44
*/
39
45
private $ file ;
40
46
41
47
/**
42
48
* @param Mime $fileMime
49
+ * @param Factory $imageFactory
43
50
* @param File $file
44
51
*/
45
52
public function __construct (
46
53
Mime $ fileMime ,
54
+ Factory $ imageFactory ,
47
55
File $ file
48
56
) {
49
57
$ this ->fileMime = $ fileMime ;
58
+ $ this ->imageFactory = $ imageFactory ;
50
59
$ this ->file = $ file ;
51
60
}
52
61
@@ -60,10 +69,8 @@ public function isValid($filePath): bool
60
69
61
70
if (in_array ($ fileMimeType , $ this ->imageMimeTypes )) {
62
71
try {
63
- //phpcs:ignore Magento2.Functions.DiscouragedFunction
64
- $ image = imagecreatefromstring ($ this ->file ->fileGetContents ($ filePath ));
65
-
66
- $ isValid = $ image ? true : false ;
72
+ $ image = $ this ->imageFactory ->create ($ filePath );
73
+ $ image ->open ();
67
74
} catch (\Exception $ e ) {
68
75
$ isValid = false ;
69
76
}
Original file line number Diff line number Diff line change @@ -104,7 +104,15 @@ public function open($filename)
104
104
$ this ->_getFileAttributes ();
105
105
106
106
try {
107
- $ this ->_imageHandler = new \Imagick ($ this ->_fileName );
107
+ if (is_callable ('exif_imagetype ' )) {
108
+ $ fileType = exif_imagetype ($ this ->_fileName );
109
+
110
+ if ($ fileType === IMAGETYPE_ICO ) {
111
+ $ filename = 'ico: ' . $ this ->_fileName ;
112
+ }
113
+ }
114
+
115
+ $ this ->_imageHandler = new \Imagick ($ filename );
108
116
} catch (\ImagickException $ e ) {
109
117
//phpcs:ignore Magento2.Exceptions.DirectThrow
110
118
throw new LocalizedException (
You can’t perform that action at this time.
0 commit comments