public static boolean saveImage(Image img, String filename)
    {

        String extension = null;
        try
        {
            int index_of_extension = filename.lastIndexOf(".");
            extension = filename.substring(index_of_extension);

            if(extension.equalsIgnoreCase(".gif") )
            {
                return saveGIF(img, filename);
            }
            else if(extension.equalsIgnoreCase(".jpg") || extension.equalsIgnoreCase(".jpeg") )
            {
                return saveJPG(img, filename);
            }
            else if(extension.equalsIgnoreCase(".bmp") )
            {
                return saveBMP(img, filename);
            }
            else if(extension.equalsIgnoreCase(".pgm") )
            {
                return savePGM(img, filename);
            }
            else if(extension.equalsIgnoreCase(".ppm") )
            {
                return savePPM(img, filename);
            }
            else
            {
                // System.out.println("Unsupported file type");
            }
        }
        catch(Exception e)
        {
            // System.out.println("Error!!" + e.toString());
        }

        // Put a message here
        return false;   //error saving file

    }