@@ -39,6 +39,8 @@ class ImageResize
39
39
40
40
protected $ source_w ;
41
41
protected $ source_h ;
42
+
43
+ protected $ source_info ;
42
44
43
45
/**
44
46
* Create instance from a strng
@@ -49,6 +51,9 @@ class ImageResize
49
51
*/
50
52
public static function createFromString ($ image_data )
51
53
{
54
+ if (empty ($ image_data ) || $ image_data === null ) {
55
+ throw new ImageResizeException ('image_data must not be empty ' );
56
+ }
52
57
$ resize = new self ('data://application/octet-stream;base64, ' . base64_encode ($ image_data ));
53
58
return $ resize ;
54
59
}
@@ -62,7 +67,17 @@ public static function createFromString($image_data)
62
67
*/
63
68
public function __construct ($ filename )
64
69
{
65
- $ image_info = @getimagesize ($ filename );
70
+
71
+ if ($ filename === null || empty ($ filename ) || (substr ($ filename ,0 ,7 ) !== 'data:// ' && !is_file ($ filename ))) {
72
+ throw new ImageResizeException ('File does not exist ' );
73
+ }
74
+
75
+ $ finfo = finfo_open (FILEINFO_MIME_TYPE );
76
+ if (strstr (finfo_file ($ finfo , $ filename ),'image ' ) === false ) {
77
+ throw new ImageResizeException ('Unsupported file type ' );
78
+ }
79
+
80
+ $ image_info = getimagesize ($ filename ,$ this ->source_info );
66
81
67
82
if (!$ image_info ) {
68
83
throw new ImageResizeException ('Could not read file ' );
@@ -107,12 +122,12 @@ public function __construct($filename)
107
122
// http://stackoverflow.com/a/28819866
108
123
public function imageCreateJpegfromExif ($ filename ){
109
124
$ img = imagecreatefromjpeg ($ filename );
110
-
111
- if (!function_exists ('exif_read_data ' )) {
125
+
126
+ if (!function_exists ('exif_read_data ' ) || ! isset ( $ this -> source_info [ ' APP1 ' ]) || strpos ( $ this -> source_info [ ' APP1 ' ], ' Exif ' ) !== 0 ) {
112
127
return $ img ;
113
128
}
114
-
115
- $ exif = @ exif_read_data ($ filename );
129
+
130
+ $ exif = exif_read_data ($ filename );
116
131
117
132
if (!$ exif || !isset ($ exif ['Orientation ' ])){
118
133
return $ img ;
0 commit comments