[pygtk] Reducing number of colors in image

Thomas Guettler hv at tbz-pariv.de
Fri Aug 19 22:16:52 WST 2011


Hi,

up to now I create previews (smaller images) like this.

Has some one a hint how I can reduce the number of colors, to
reduce the file size?


def scale2file(width_max, height_max, filename, outfile):
    pixbuf=gtk.gdk.pixbuf_new_from_file(filename)
    width_orig=pixbuf.get_width()
    height_orig=pixbuf.get_height()
    width, height = max_width_height(
        width_orig, height_orig,
        width_max, height_max)
    pixbuf=pixbuf.scale_simple(width, height, gtk.gdk.INTERP_BILINEAR)
    if pixbuf:
        pixbuf.save(outfile, 'png')
    else:
        logging.error('pixbuf.scale_simple failed: %s' % filename)
        os.symlink(filename, outfile)



-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


More information about the pygtk mailing list