Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=xbdmenu.git;a=commitdiff;h=4e2c89991b3073b8526e78bdd594c3b7936078e8

commit 4e2c89991b3073b8526e78bdd594c3b7936078e8
Author: James Buren <r...@frugalware.org>
Date:   Tue Jun 9 00:04:05 2009 -0500

img.c
* update

diff --git a/img.c b/img.c
new file mode 100644
index 0000000..6ef2774
--- /dev/null
+++ b/img.c
@@ -0,0 +1,51 @@
+#include <string.h>
+#include <errno.h>
+#include "img.h"
+#include "util.h"
+
+gdImagePtr gdImageCreateFromFile(const char *name) {
+       char *end; FILE *file; gdImagePtr img;
+
+       /* Check for invalid arguments */
+       if( !name ) {
+               eprintf("Invalid name passed to gdImageCreateFromFile().\n");
+               return NULL;
+       }
+
+       end = strrchr(name,'.');
+
+       /* Check if strrchr() failed */
+       if( !end++ ) {
+               eprintf("Failed to retrieve file extension: %s\n",name);
+               return NULL;
+       }
+
+       file = fopen(name,"rb");
+
+       /* Check if fopen() failed */
+       if( !file ) {
+               eprintf("%s: %s\n",strerror(errno),name);
+               return NULL;
+       }
+
+       if( !strcmp(end,"png") ) {
+               img = gdImageCreateFromPng(file);
+       }
+       /* Check if it is an unknown image type */
+       else {
+               eprintf("Unrecognized image file: %s\n",name);
+               fclose(file);
+               return NULL;
+       }
+
+       /* Check if the image failed to load */
+       if( !img ) {
+               eprintf("Failed to load image file: %s\n",name);
+               fclose(file);
+               return NULL;
+       }
+
+       fclose(file);
+
+       return img;
+}
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to