2121 */
2222package com .koadweb .javafpdf ;
2323
24+ import com .koadweb .javafpdf .util .Compressor ;
2425import java .awt .color .ColorSpace ;
2526import java .awt .image .BufferedImage ;
2627import java .io .File ;
3738import java .util .Locale ;
3839import java .util .Map ;
3940import java .util .Set ;
40-
4141import javax .imageio .ImageIO ;
4242
43- import com .koadweb .javafpdf .util .Compressor ;
44-
4543/**
4644 * Faithful Java port of <a href="http://www.fpdf.org">FPDF for PHP</a>.
4745 *
@@ -1814,6 +1812,7 @@ public float getY() {
18141812 * link identifier for the image
18151813 * @throws IOException
18161814 */
1815+ @ SuppressWarnings ("fallthrough" )
18171816 public void Image (final String file , final Coordinate coords , final float w , final float h , final ImageType type ,
18181817 final int link ) throws IOException {
18191818 Map <String , Object > info = null ;
@@ -1830,12 +1829,20 @@ public void Image(final String file, final Coordinate coords, final float w, fin
18301829 } else {
18311830 type1 = type ;
18321831 }
1833- if (ImageType .PNG .equals (type1 )) {
1834- info = this ._parsepng (new File (file ));
1835- } else if (ImageType .JPEG .equals (type1 )) {
1836- info = this ._parsejpg (new File (file ));
1837- } else {
1838- throw new IOException ("Image type not supported." );
1832+ File f = new File (file );
1833+ switch (type1 ) {
1834+ case GIF :
1835+ // gifs: convert to png first
1836+ ImageIO .write (ImageIO .read (f ), "png" , f );
1837+ // fallthrough!
1838+ case PNG :
1839+ info = this ._parsepng (f );
1840+ break ;
1841+ case JPEG :
1842+ info = this ._parsejpg (f );
1843+ break ;
1844+ default :
1845+ throw new IOException ("Image type not supported." );
18391846 }
18401847 // FIXME no support for other formats
18411848 this .images .put (file , info );
0 commit comments