public static Image trimTextImage(Image im, int width, int height)
    {
        /*
            Due to the slight inaccuracy of the font sizes, a text image may
            not need all the height allocated to it.  This method will crop and
            image so that all rows that are totally transparent are eliminated.

            This method assumes there is at least SOME text in th image.  Additionally,
            I do not bother cropping columns.
        */

        int transparent_pic = JIPTsettings.CLEAR_PIXEL_3; // Transparent pic
        //main_frame.getJIPTsettings().getClearPixelColor();

        int pix[] = JIPTUtilities.getPixelArray(im);

        // Scan each row.  Stop when the end of the array is reached or
        // a non-transparent color is hit.
        int count = 0; // A counter that keeps track of how many rows are transparent

        for(int i = 1; i < pix.length; i++)
        {
            int alpha = (pix[i] >> 24) & 0xff;
            if(alpha != 0)
                break;

            if(i%width == 0)
                count++;
        }
        // System.out.println("Count = " + count);
        int new_pix[] = new int[(height - count)*width];
        int index = 0;
        for(int i = count*width; i < pix.length; i++)
        {
            int alpha = (pix[i] >> 24) & 0xff;
            if(alpha == 0)
                new_pix[index] = transparent_pic;
            else
                new_pix[index] = pix[i];
            index++;
        }

        Image new_im = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(width, height - count, new_pix, 0, width));
        return new_im;

    }