[libGD] #211 [Task opened] aggregate gdImageCreateFromFile function

[email protected] Wed, 8 Jul 2009 19:35:12 +0200 (CEST)
Newsgroups php.gd.bugs
Message-ID <[email protected]>
THIS IS AN AUTOMATED MESSAGE, DO NOT REPLY.

A new Flyspray task has been opened.  Details are below. 

User who did this - James Buren (ryuo) 

Attached to Project - libGD
Summary - aggregate gdImageCreateFromFile function
Task Type - Feature Request
Category - Image Import/Export
Status - Unconfirmed
Assigned To - 
Operating System - All
Severity - Low
Priority - Normal
Reported Version - 2.0.35
Due in Version - Undecided
Due Date - Undecided
Details - I'd like an aggregate function for all the gdImageCreateFrom* functions. I wrote one against 2.0.35. I would appreciate it if it ends up being used. Thanks. Its below.

#include <gd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>

char *gdImageCreateFromFile(const char *path,gdImage **image) {
    FILE *file = NULL;
    char *err = NULL;
    char *ext;

    file = fopen(path,"rb");

    if(!file) {
        err = strerror(errno);
        goto BAIL;
    }

    ext = strrchr(path,'.');

    if(!ext++) {
        err = "Failed to retrieve file extension";
        goto BAIL;
    }

    if( !strcasecmp(ext,"png") )
        *image = gdImageCreateFromPng(file);
    else if( !strcasecmp(ext,"gif") )
        *image = gdImageCreateFromGif(file);
    else if( !strcasecmp(ext,"jpg") || !strcasecmp(ext,"jpeg") )
        *image = gdImageCreateFromJpeg(file);
    else if( !strcasecmp(ext,"wbmp") )
        *image = gdImageCreateFromWBMP(file);
    else if( !strcasecmp(ext,"gd") )
        *image = gdImageCreateFromGd(file);
    else if( !strcasecmp(ext,"gd2") )
        *image = gdImageCreateFromGd2(file);
    else {
        err = "Unrecognized image format";
        goto BAIL;
    }

    if( !*image ) {
        err = "Failed to load image";
        goto BAIL;
    }

    BAIL:

    if(file)
        fclose(file);

    return err;
}

int main(void) {
    gdImagePtr image;
    char *test;

    test = gdImageCreateFromFile("test.PNG",&image);

    if(test)
        printf("%s\n",test);

    if(image)
        gdImageDestroy(image);

    return 0;
}

More information can be found at the following URL:
http://bugs.libgd.org/?do=details&task_id=211

You are receiving this message because you have requested it from the Flyspray bugtracking system.  If you did not expect this message or don't want to receive mails in future, you can change your notification settings at the URL shown above.