[cairo] Saving surfaces as GIF/ low color PNG

Simon Budig simon at budig.de
Tue Aug 12 14:31:46 PDT 2008


Mohit Sindhwani (tech at onghu.com) wrote:
> For one of the applications where we are serving up dynamically created 
> images on the web, I was thinking of using Cairo.  Now, Cairo produces 
> PNG files, which at default can be quite large.  I was wondering if 
> people here are using something to convert the image/ PNG surface to a 
> GIF file or such.  I'm on Windows for this application.

(just a sidenote - if saving the *same* image content PNGs are basically
always smaller than GIFs.)

When using cairo_image_surface_create() you are not limited to the PNG
format. Cairo has some convenience functions to write an image surface
to PNG, but you can also get the image data directly via
cairo_image_surface_get_data(). Then you can throw any library functions
at this data, e.g. encoding as JPEG/GIF/PNG (via libpng) or whatever.
That should suit your needs.

Bye,
        Simon

-- 
              simon at budig.de              http://simon.budig.de/


More information about the cairo mailing list