@@ -282,16 +282,15 @@ public static Image getBmpImage(byte[] bytes, boolean noHeader, int size) {
282282 }
283283
284284 /**
285- * Return a GifImage object. This object cannot be
285+ * Return a GifImage object. This object cannot be added to a document
286286 * @param bytes
287287 * @return
288288 */
289289 public static GifImage getGifImage (byte [] bytes ) {
290290 byte [] imageType = readImageType (bytes );
291291 if (imageTypeIs (imageType , gif )) {
292292 GifImage image = new GifImage (bytes );
293- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
294- GifImageHelper .processImage (image , baos );
293+ GifImageHelper .processImage (image );
295294 return image ;
296295 }
297296 throw new IllegalArgumentException ("GIF image expected." );
@@ -307,8 +306,7 @@ public static Image getGifFrame(URL url, int frame) {
307306 byte [] imageType = readImageType (url );
308307 if (imageTypeIs (imageType , gif )) {
309308 GifImage image = new GifImage (url );
310- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
311- GifImageHelper .processImage (image , baos , frame - 1 );
309+ GifImageHelper .processImage (image , frame - 1 );
312310 return image .getFrames ().get (frame - 1 );
313311 }
314312 throw new IllegalArgumentException ("GIF image expected." );
@@ -324,8 +322,7 @@ public static Image getGifFrame(byte[] bytes, int frame) {
324322 byte [] imageType = readImageType (bytes );
325323 if (imageTypeIs (imageType , gif )) {
326324 GifImage image = new GifImage (bytes );
327- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
328- GifImageHelper .processImage (image , baos , frame - 1 );
325+ GifImageHelper .processImage (image , frame - 1 );
329326 return image .getFrames ().get (frame - 1 );
330327 }
331328 throw new IllegalArgumentException ("GIF image expected." );
@@ -341,9 +338,8 @@ public static List<Image> getGifFrames(byte[] bytes, int[] frameNumbers) {
341338 byte [] imageType = readImageType (bytes );
342339 if (imageTypeIs (imageType , gif )) {
343340 GifImage image = new GifImage (bytes );
344- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
345341 Arrays .sort (frameNumbers );
346- GifImageHelper .processImage (image , baos , frameNumbers [frameNumbers .length - 1 ] - 1 );
342+ GifImageHelper .processImage (image , frameNumbers [frameNumbers .length - 1 ] - 1 );
347343 List <Image > frames = new ArrayList <>();
348344 for (int frame : frameNumbers ) {
349345 frames .add (image .getFrames ().get (frame - 1 ));
@@ -363,9 +359,8 @@ public static List<Image> getGifFrames(URL url, int[] frameNumbers) {
363359 byte [] imageType = readImageType (url );
364360 if (imageTypeIs (imageType , gif )) {
365361 GifImage image = new GifImage (url );
366- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
367362 Arrays .sort (frameNumbers );
368- GifImageHelper .processImage (image , baos , frameNumbers [frameNumbers .length - 1 ] - 1 );
363+ GifImageHelper .processImage (image , frameNumbers [frameNumbers .length - 1 ] - 1 );
369364 List <Image > frames = new ArrayList <>();
370365 for (int frame : frameNumbers ) {
371366 frames .add (image .getFrames ().get (frame - 1 ));
@@ -375,6 +370,36 @@ public static List<Image> getGifFrames(URL url, int[] frameNumbers) {
375370 throw new IllegalArgumentException ("GIF image expected." );
376371 }
377372
373+ /**
374+ * Returns <CODE>List</CODE> of gif image frames
375+ * @param bytes byte array of gif image
376+ * @return all frames of gif image
377+ */
378+ public static List <Image > getGifFrames (byte [] bytes ) {
379+ byte [] imageType = readImageType (bytes );
380+ if (imageTypeIs (imageType , gif )) {
381+ GifImage image = new GifImage (bytes );
382+ GifImageHelper .processImage (image );
383+ return image .getFrames ();
384+ }
385+ throw new IllegalArgumentException ("GIF image expected." );
386+ }
387+
388+ /**
389+ * Returns <CODE>List</CODE> of gif image frames
390+ * @param url url of gif image
391+ * @return all frames of gif image
392+ */
393+ public static List <Image > getGifFrames (URL url ) {
394+ byte [] imageType = readImageType (url );
395+ if (imageTypeIs (imageType , gif )) {
396+ GifImage image = new GifImage (url );
397+ GifImageHelper .processImage (image );
398+ return image .getFrames ();
399+ }
400+ throw new IllegalArgumentException ("GIF image expected." );
401+ }
402+
378403 public static Image getJbig2Image (URL url , int page ) {
379404 if (page < 1 )
380405 throw new IllegalArgumentException ("The page number must be greater than 0" );
@@ -508,8 +533,7 @@ private static Image getImageInstance(URL source, boolean recoverImage) {
508533 byte [] imageType = readImageType (source );
509534 if (imageTypeIs (imageType , gif )) {
510535 GifImage image = new GifImage (source );
511- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
512- GifImageHelper .processImage (image , baos , 0 );
536+ GifImageHelper .processImage (image , 0 );
513537 return image .getFrames ().get (0 );
514538 } else if (imageTypeIs (imageType , jpeg )) {
515539 Image image = new JpegImage (source );
@@ -553,8 +577,7 @@ private static Image getImageInstance(byte[] bytes, boolean recoverImage) {
553577 byte [] imageType = readImageType (bytes );
554578 if (imageTypeIs (imageType , gif )) {
555579 GifImage image = new GifImage (bytes );
556- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
557- GifImageHelper .processImage (image , baos , 0 );
580+ GifImageHelper .processImage (image , 0 );
558581 return image .getFrames ().get (0 );
559582 } else if (imageTypeIs (imageType , jpeg )) {
560583 Image image = new JpegImage (bytes );
0 commit comments