@@ -45,11 +45,10 @@ class ImageResize
4545 * @return ImageResize
4646 * @throws \exception
4747 */
48- public static function createFromString ($ imageData )
48+ public static function createFromString ($ image_data )
4949 {
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 ;
5352 }
5453
5554 /**
@@ -58,55 +57,9 @@ public static function createFromString($imageData)
5857 * @param string|null $filename
5958 * @throws \Exception
6059 */
61- public function __construct ($ filename = null )
60+ public function __construct ($ filename )
6261 {
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 );
11063 }
11164
11265 /**
@@ -121,7 +74,7 @@ public function loadFromFile($filename)
12174 $ image_info = @getimagesize ($ filename );
12275
12376 if (!$ image_info ) {
124- throw new \Exception ('Could not read ' . ( $ filename ?: ' file ') );
77+ throw new \Exception ('Could not read file ' );
12578 }
12679
12780 list (
0 commit comments