Method

GdkPixbufPixbufsave

Declaration [src]

gboolean
gdk_pixbuf_save (
  GdkPixbuf* pixbuf,
  const char* filename,
  const char* type,
  GError** error,
  ...
)

Description [src]

Saves pixbuf to a file in format type. By default, “jpeg”, “png”, “ico” and “bmp” are possible file formats to save in, but more formats may be installed. The list of all writable formats can be determined in the following way:

void add_if_writable (GdkPixbufFormat *data, GSList **list)
{
  if (gdk_pixbuf_format_is_writable (data))
    *list = g_slist_prepend (*list, data);
}

GSList *formats = gdk_pixbuf_get_formats ();
GSList *writable_formats = NULL;
g_slist_foreach (formats, add_if_writable, &writable_formats);
g_slist_free (formats);

If error is set, FALSE will be returned. Possible errors include those in the GDK_PIXBUF_ERROR domain and those in the G_FILE_ERROR domain.

The variable argument list should be NULL-terminated; if not empty, it should contain pairs of strings that modify the save parameters. For example:

gdk_pixbuf_save (pixbuf, handle, "jpeg", &error, "quality", "100", NULL);

Currently only few parameters exist.

JPEG images can be saved with a “quality” parameter; its value should be in the range [0, 100]. JPEG and PNG density can be set by setting the “x-dpi” and “y-dpi” parameters to the appropriate values in dots per inch.

Text chunks can be attached to PNG images by specifying parameters of the form “tEXt::key”, where key is an ASCII string of length 1-79. The values are UTF-8 encoded strings. The PNG compression level can be specified using the “compression” parameter; it’s value is in an integer in the range of [0, 9].

ICC color profiles can also be embedded into PNG, JPEG and TIFF images. The “icc-profile” value should be the complete ICC profile encoded into base64.

char *contents;
gsize length;

// icm_path is set elsewhere
g_file_get_contents (icm_path, &contents, &length, NULL);

char *contents_encode = g_base64_encode ((const guchar *) contents, length);

gdk_pixbuf_save (pixbuf, handle, "png", &error, "icc-profile", contents_encode, NULL);

TIFF images recognize:

  1. a “bits-per-sample” option (integer) which can be either 1 for saving bi-level CCITTFAX4 images, or 8 for saving 8-bits per sample
  2. a “compression” option (integer) which can be 1 for no compression, 2 for Huffman, 5 for LZW, 7 for JPEG and 8 for DEFLATE (see the libtiff documentation and tiff.h for all supported codec values)
  3. an “icc-profile” option (zero-terminated string) containing a base64 encoded ICC color profile.

ICO images can be saved in depth 16, 24, or 32, by using the “depth” parameter. When the ICO saver is given “x_hot” and “y_hot” parameters, it produces a CUR instead of an ICO.

This method is not directly available to language bindings.

Parameters

filename

Type: const char*

Name of file to save.

The data is owned by the caller of the method.
The value is a file system path, using the OS encoding.
type

Type: const char*

Name of file format.

The data is owned by the caller of the method.
The value is a NUL terminated UTF-8 string.
error

Type: GError

Return location for error.

The argument can be NULL.
The data is owned by the caller of the method.
...

Type: 

List of key-value save options, followed by NULL

Return value

Type: gboolean

TRUE on success, and FALSE otherwise.