GdkPixbuf Constructor

GdkPixbuf::new_from_file (string filename);

This constructor creates a GdkPixbuf object filled with the image information available in filename. If an error occurs (e.g. file doesn't exist), an exceptionof type PhpGtkGErrorException is thrown.

Gdk supports loading a number of image formats, including .jpg, .png and .gif. On Windows, you need a dll for each file type in the pixbufloaders/ folder of your Gtk installation, e.g. libpixbufloader-png.dll or libpixbufloader-jpeg.dll.

Example 4. Loading an image file and catching errors

//Examle: Loading an image file
try {
    $pixbuf = GdkPixbuf::new_from_file('test.png');
} catch (Exception $e) {
    //Here we catch errors that could occur
    echo "An error occured:\n";
    echo $e->getMessage() . "\n";