File Loading

## File Loading File Loading — Loading a pixbuf from a file. |

## Synopsis

    #include <gdk-pixbuf/gdk-pixbuf.h>

    GdkPixbuf*  gdk_pixbuf_new_from_file        (const char *filename,
                                                 GError **error);
    GdkPixbuf*  gdk_pixbuf_new_from_file_at_size
                                                (const char *filename,
                                                 int width,
                                                 int height,
                                                 GError **error);
    GdkPixbufFormat* gdk_pixbuf_get_file_info   (const gchar *filename,
                                                 gint *width,
                                                 gint *height);

## Description

The gdk-pixbuf library provides a simple mechanism for loading an image from a file in synchronous fashion. This means that the library takes control of the application while the file is being loaded; from the user's point of view, the application will block until the image is done loading.

This interface can be used by applications in which blocking is acceptable while an image is being loaded. It can also be used to load small images in general. Applications that need progressive loading can use the GdkPixbufLoader functionality instead.

## Details

### gdk_pixbuf_new_from_file ()

    GdkPixbuf*  gdk_pixbuf_new_from_file        (const char *filename,
                                                 GError **error);

Creates a new pixbuf by loading an image from a file. The file format is detected automatically. If `NULL` is returned, then `error` will be set. Possible errors are in the GDK_PIXBUF_ERROR and G_FILE_ERROR domains.

`filename` : | Name of file to load.
`error` : | Return location for an error
Returns : | A newly-created pixbuf with a reference count of 1, or `NULL` if any of several error conditions occurred: the file could not be opened, there was no loader for the file's format, there was not enough memory to allocate the image buffer, or the image file contained invalid data.

### gdk_pixbuf_new_from_file_at_size ()

    GdkPixbuf*  gdk_pixbuf_new_from_file_at_size
                                                (const char *filename,
                                                 int width,
                                                 int height,
                                                 GError **error);

Creates a new pixbuf by loading an image from a file. The file format is detected automatically. If `NULL` is returned, then `error` will be set. Possible errors are in the GDK_PIXBUF_ERROR and G_FILE_ERROR domains. The image will be scaled to fit in the requested size, preserving its aspect ratio.

`filename` : | Name of file to load.
`width` : | The width the image should have
`height` : | The height the image should have
`error` : | Return location for an error
Returns : | A newly-created pixbuf with a reference count of 1, or `NULL` if any of several error conditions occurred: the file could not be opened, there was no loader for the file's format, there was not enough memory to allocate the image buffer, or the image file contained invalid data.

Since 2.4

### gdk_pixbuf_get_file_info ()

    GdkPixbufFormat* gdk_pixbuf_get_file_info   (const gchar *filename,
                                                 gint *width,
                                                 gint *height);

Parses an image file far enough to determine its format and size.

`filename` : | The name of the file to identify.
`width` : | Return location for the width of the image, or `NULL`
`height` : | Return location for the height of the image, or `NULL`
Returns : | A GdkPixbufFormat describing the image format of the file or `NULL` if the image format wasn't recognized. The return value is owned by GdkPixbuf and should not be freed.

Since 2.4

## See Also

GdkPixbufLoader.