gdImageCreateFromPng / fopen

zzuina의 이미지

URL을 입력받아 이미지를 /tmp 디렉토리에 다운로드 받고 이미지의 전체 픽셀의 rgb값을 뽑아내려고 합니다.
현재 아래 코드처럼 구현을 해놓았는데요,

jpg URL을 주면 fopen에서 에러가 나고,
png URL을 주면 gdImageCreateFromPng에서 에러가 나는 듯 싶습니다.

무엇이 잘못된건지 못찾겠네요 ㅠㅠ
고수님들의 도움을 부탁드립니다 >_ <

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gd.h>
 
#define BUF_SIZE	1024
#define MAX_URL_LEN	1024
 
char url[MAX_URL_LEN];		// URL String
char fileName[BUF_SIZE];	// File Name
 
int dw_file();
int make_rgb_file();
 
int main(int argc, char *argv[])
{
	if(argv[1]!=0) {
		strncpy(url, argv[1], MAX_URL_LEN);
	} else {
		printf("ERROR: URL input error!\n");
		return -1;
	}
 
	/* download file from URL */
	dw_file();	
	/* extract the extension and call the function */
	make_rgb_file();
	return 0;
}
 
int dw_file()
{
	char wg_cmd[BUF_SIZE] = "wget ";		// wget command
	char wg_cmd_opt[100] = " -P /tmp -nH -r";
	char bn_cmd[BUF_SIZE] = "basename ";		// basename command
	FILE *bn_result;
 
	/* command: wget [URL] -P /tmp -nH -r
	   -P /tmp: set download directory
	   -nH: no host-directories
	   -r: re-downloading and overwriting */
	strncat(wg_cmd, url, BUF_SIZE);
	strncat(wg_cmd, wg_cmd_opt, BUF_SIZE);
	/* command: basename [URL] */
	strncat(bn_cmd, url, BUF_SIZE);
 
	/* execute wget shell command */
	if(system(wg_cmd)!=0) {
		printf("ERROR: wget command error!\n");
		return -1;
	}
	printf("\n\n");
 
	/* execute basename shell command and get file name */
	if((bn_result = popen(bn_cmd, "r"))!=0) {
		fgets(fileName, BUF_SIZE, bn_result);
		printf("FILENAME: %s\n", fileName);
	} else {
		printf("ERROR: basename command error!\n");
		return -1;
	}
	return 0;
}
 
int make_rgb_file()
{
	char *ext;
	char path[BUF_SIZE] = "/tmp/";
	FILE *fp;
	gdImagePtr im;
 
	ext = rindex(fileName, (int)'.');
	strncat(path, fileName, BUF_SIZE);
	printf("%s\n", path);
 
	if((fp=fopen(path, "rb")) == NULL ) {
		printf("ERROR: file open error!\n");
		return -1;
	} else {
		if(!strncmp(ext,".jpg",4) || !strncmp(ext,".jpeg",4) || 
		   !strncmp(ext,".JPG",4) || !strncmp(ext,".JPEG",4)) {
			printf("jpg area\n");
		} else if(!strncmp(ext,".gif",3) || !strncmp(ext,".GIF",3)) {
			printf("gif area\n");
		} else if(!strncmp(ext,".png",3) || !strncmp(ext,".PNG",3)) {
			printf("png area\n");
			if((im = gdImageCreateFromPng(fp))==NULL) {
				printf("ERROR: image create error!\n");
				return -1;
			} else {
				printf("%d %d\n", im->sx, im->sy);
			}
		} else printf("What is this?\n");
	}
	fclose(fp);
	gdImageDestroy(im);
	return 0;
}
Hyun의 이미지

답변은 아니나...
[ code ] 태그보다는
< code > 태그를 쓰면 소스코드가 더 예쁘게 출력되더군요...

zzuina의 이미지

< code > 태그를 쓴건데도 그르네요 ^^; 왜 탭이 안먹히는 걸까요...;;;

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.