@@ -137,72 +137,70 @@ private function parseSize()
137
137
/**
138
138
* Parses the image size for PNG
139
139
*
140
- * @return array
140
+ * @return array|null
141
141
*/
142
142
private function parseSizeForPNG ()
143
143
{
144
- $ chars = $ this ->getChars (25 );
145
-
146
- return unpack ( " N* " , substr ( $ chars , 16 , 8 ));
144
+ if (( $ chars = $ this ->getChars (25 ))) {
145
+ return unpack ( " N* " , substr ( $ chars , 16 , 8 ));
146
+ }
147
147
}
148
148
149
149
/**
150
150
* Parses the image size for GIF
151
151
*
152
- * @return array
152
+ * @return array|null
153
153
*/
154
154
private function parseSizeForGIF ()
155
155
{
156
- $ chars = $ this ->getChars (11 );
157
-
158
- return unpack ( " S* " , substr ( $ chars , 6 , 4 ));
156
+ if (( $ chars = $ this ->getChars (11 ))) {
157
+ return unpack ( " S* " , substr ( $ chars , 6 , 4 ));
158
+ }
159
159
}
160
160
161
161
/**
162
162
* Parses the image size for BMP
163
163
*
164
- * @return array
164
+ * @return array|null
165
165
*/
166
166
private function parseSizeForBMP ()
167
167
{
168
- $ chars = $ this ->getChars (29 );
169
- $ chars = substr ($ chars , 14 , 14 );
170
- $ type = unpack ('C ' , $ chars );
168
+ if (( $ chars = $ this ->getChars (29 ))) {
169
+ $ chars = substr ($ chars , 14 , 14 );
170
+ $ type = unpack ('C ' , $ chars );
171
171
172
- return (reset ($ type ) == 40 ) ? unpack ('L* ' , substr ($ chars , 4 )) : unpack ('L* ' , substr ($ chars , 4 , 8 ));
172
+ return (reset ($ type ) == 40 ) ? unpack ('L* ' , substr ($ chars , 4 )) : unpack ('L* ' , substr ($ chars , 4 , 8 ));
173
+ }
173
174
}
174
175
175
176
/**
176
177
* Parses the image size for JPEG
177
178
*
178
- * @return array
179
+ * @return array|null
179
180
*/
180
181
private function parseSizeForJPEG ()
181
182
{
182
183
$ state = null ;
183
- $ i = 0 ;
184
+ $ skip = 0 ;
184
185
185
186
while (true ) {
186
187
switch ($ state ) {
187
- default :
188
- $ this ->getChars (2 );
189
- $ state = 'started ' ;
190
- break ;
191
-
192
188
case 'started ' :
193
- $ b = $ this ->getByte ();
194
- if ($ b === false ) return false ;
189
+ if (($ b = $ this ->getByte ()) === false ) {
190
+ return false ;
191
+ }
195
192
196
- $ state = $ b == 0xFF ? 'sof ' : 'started ' ;
193
+ $ state = $ b === 0xFF ? 'sof ' : 'started ' ;
197
194
break ;
198
195
199
196
case 'sof ' :
200
197
$ b = $ this ->getByte ();
198
+
201
199
if (in_array ($ b , range (0xe0 , 0xef ))) {
202
200
$ state = 'skipframe ' ;
203
201
} elseif (in_array ($ b , array_merge (range (0xC0 ,0xC3 ), range (0xC5 ,0xC7 ), range (0xC9 ,0xCB ), range (0xCD ,0xCF )))) {
204
202
$ state = 'readsize ' ;
205
- } elseif ($ b == 0xFF ) {
203
+ } elseif ($ b === 0xFF ) {
206
204
$ state = 'sof ' ;
207
205
} else {
208
206
$ state = 'skipframe ' ;
@@ -223,6 +221,10 @@ private function parseSizeForJPEG()
223
221
$ c = $ this ->getChars (7 );
224
222
225
223
return array ($ this ->readInt (substr ($ c , 5 , 2 )), $ this ->readInt (substr ($ c , 3 , 2 )));
224
+
225
+ default :
226
+ $ this ->getChars (2 );
227
+ $ state = 'started ' ;
226
228
}
227
229
}
228
230
}
@@ -268,10 +270,13 @@ private function getChars($n)
268
270
*/
269
271
private function getByte ()
270
272
{
271
- $ c = $ this ->getChars (1 );
272
- $ b = unpack ("C " , $ c );
273
+ if (( $ c = $ this ->getChars (1 ))) {
274
+ $ b = unpack ("C " , $ c );
273
275
274
- return reset ($ b );
276
+ return reset ($ b );
277
+ }
278
+
279
+ return false ;
275
280
}
276
281
277
282
/**
0 commit comments