@@ -45,11 +45,10 @@ class ImageResize
45
45
* @return ImageResize
46
46
* @throws \exception
47
47
*/
48
- public static function createFromString ($ imageData )
48
+ public static function createFromString ($ image_data )
49
49
{
50
- $ s = new self ();
51
- $ s ->loadFromString ($ imageData );
52
- return $ s ;
50
+ $ resize = new self ('data://application/octet-stream;base64, ' . base64_encode ($ image_data ));
51
+ return $ resize ;
53
52
}
54
53
55
54
/**
@@ -58,55 +57,9 @@ public static function createFromString($imageData)
58
57
* @param string|null $filename
59
58
* @throws \Exception
60
59
*/
61
- public function __construct ($ filename = null )
60
+ public function __construct ($ filename )
62
61
{
63
- if ($ filename !== null ) {
64
- $ this ->loadFromFile ($ filename );
65
- } else {
66
- // if no filename is provided, we want to throw an exception if
67
- // the object was not created in one of it's static method
68
- $ backtrace = debug_backtrace ();
69
-
70
- if (!isset ($ backtrace [1 ]['class ' ]) || $ backtrace [1 ]['class ' ] != __CLASS__ ) {
71
- throw new \Exception ('No image provided ' );
72
- }
73
- }
74
- }
75
-
76
- /**
77
- * Load image from string
78
- *
79
- * @param string $imagedata
80
- * @return ImageResize
81
- * @throws \Exception
82
- */
83
- public function loadFromString ($ imagedata )
84
- {
85
- $ image_info = @getimagesize ('data://application/octet-stream;base64, ' . base64_encode ($ imagedata ));
86
-
87
- if (!$ image_info ) {
88
- throw new \Exception ('Could not load image from string ' );
89
- }
90
-
91
- list (
92
- $ this ->original_w ,
93
- $ this ->original_h ,
94
- $ this ->source_type
95
- ) = $ image_info ;
96
-
97
- switch ($ this ->source_type ) {
98
- case IMAGETYPE_GIF :
99
- case IMAGETYPE_JPEG :
100
- case IMAGETYPE_PNG :
101
- $ this ->source_image = imagecreatefromstring ($ imagedata );
102
- break ;
103
-
104
- default :
105
- throw new \Exception ('Unsupported image type ' );
106
- break ;
107
- }
108
-
109
- return $ this ->resize ($ this ->getSourceWidth (), $ this ->getSourceHeight ());
62
+ $ this ->loadFromFile ($ filename );
110
63
}
111
64
112
65
/**
@@ -121,7 +74,7 @@ public function loadFromFile($filename)
121
74
$ image_info = @getimagesize ($ filename );
122
75
123
76
if (!$ image_info ) {
124
- throw new \Exception ('Could not read ' . ( $ filename ?: ' file ') );
77
+ throw new \Exception ('Could not read file ' );
125
78
}
126
79
127
80
list (
0 commit comments