cvs: pecl /iptcdata CREDITS config.m4 iptcdata.c php_iptcdata.h
| From: | Manfred Weber | Date: | Tue, 14 Nov 2006 22:24:20 +0000 |
| Subject: | cvs: pecl /iptcdata CREDITS config.m4 iptcdata.c php_iptcdata.h | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-6635@lists.php.net to get a copy of this message | ||
crafics Tue Nov 14 22:24:20 2006 UTC
Added files:
/pecl/iptcdata CREDITS config.m4 iptcdata.c php_iptcdata.h
Log:
iptcdata init, some functions already work
http://cvs.php.net/viewvc.cgi/pecl/iptcdata/config.m4?view=markup&rev=1.1 Index: pecl/iptcdata/config.m4 +++ pecl/iptcdata/config.m4 dnl $Id: config.m4,v 1.1 2006/11/14 22:24:20 crafics Exp $ dnl config.m4 for extension iptcdata PHP_ARG_WITH(iptcdata, for iptcdata support, [ --with-iptcdata Include iptcdata support]) if test "$PHP_IPTCDATA" != "no"; then SEARCH_PATH="/usr/local /usr" # you might want to change this SEARCH_FOR="/include/libiptcdata/iptc-data.h" # you most likely want to change this if test -r $PHP_IPTCDATA/$SEARCH_FOR; then # path given as parameter IPTCDATA_DIR=$PHP_IPTCDATA else # search default path list AC_MSG_CHECKING([for iptcdata files in default path]) for i in $SEARCH_PATH ; do if test -r $i/$SEARCH_FOR; then IPTCDATA_DIR=$i AC_MSG_RESULT(found in $i) fi done fi if test -z "$IPTCDATA_DIR"; then AC_MSG_RESULT([not found]) AC_MSG_ERROR([Please reinstall the iptcdata distribution]) fi PHP_ADD_INCLUDE($IPTCDATA_DIR/include) PHP_ADD_LIBRARY_WITH_PATH(iptcdata, $PHP_IPTCDATA_DIR/lib, IPTCDATA_SHARED_LIBADD) AC_CHECK_LIB(iptcdata, iptc_data_new_from_jpeg, [ AC_DEFINE(HAVE_IPTCDATALIB,1,[ ]) ], [ AC_MSG_ERROR(iptcdata library not found or wrong version) ],) PHP_SUBST(IPTCDATA_SHARED_LIBADD) PHP_NEW_EXTENSION(iptcdata, iptcdata.c, $ext_shared) fi http://cvs.php.net/viewvc.cgi/pecl/iptcdata/iptcdata.c?view=markup&rev=1.1 Index: pecl/iptcdata/iptcdata.c +++ pecl/iptcdata/iptcdata.c /* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2006 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: | +----------------------------------------------------------------------+ */ /* $Id: iptcdata.c,v 1.1 2006/11/14 22:24:20 crafics Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_iptcdata.h" #include "libiptcdata/iptc-data.h" #include "libiptcdata/iptc-dataset.h" #include "libiptcdata/iptc-jpeg.h" #include "libiptcdata/iptc-log.h" #include "libiptcdata/iptc-mem.h" #include "libiptcdata/iptc-tag.h" #include "libiptcdata/iptc-utils.h" #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif IptcRecord record; IptcTag tag; /* If you declare any globals in php_iptcdata.h uncomment this: ZEND_DECLARE_MODULE_GLOBALS(iptcdata) */ /* True global resources - no need for thread safety here */ static int le_iptcdata; static int le_iptcdataset; PHP_FUNCTION(iptc_data_new) { IptcData *d; d = iptc_data_new (); if(!d){ RETURN_FALSE; } ZEND_REGISTER_RESOURCE(return_value, d, le_iptcdata); } PHP_FUNCTION(iptc_data_new_from_jpeg) { char *filename; int filenamelen; IptcData *d; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filenamelen) == FAILURE) { RETURN_FALSE; } d = iptc_data_new_from_jpeg(filename); if (!d) { RETURN_FALSE; } ZEND_REGISTER_RESOURCE(return_value, d, le_iptcdata); } PHP_FUNCTION(iptc_dataset_new) { IptcDataSet *ds; ds = iptc_dataset_new (); if(!ds){ RETURN_FALSE; } ZEND_REGISTER_RESOURCE(return_value, ds, le_iptcdataset); } PHP_FUNCTION(iptc_dataset_set_tag) { IptcDataSet *iptcdataset; zval *ziptcdataset; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ziptcdataset) == FAILURE) { RETURN_FALSE; } ZEND_FETCH_RESOURCE(iptcdataset, IptcDataSet*, &ziptcdataset, -1, PHP_IPTCDATASET_RES_NAME, le_iptcdataset); iptc_dataset_set_tag (iptcdataset, record, tag); RETURN_TRUE; } PHP_FUNCTION(iptc_dataset_set_data) { IptcDataSet *iptcdataset; zval *ziptcdataset; char *data; int datalen; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &ziptcdataset, &data, &datalen) == FAILURE) { RETURN_FALSE; } ZEND_FETCH_RESOURCE(iptcdataset, IptcDataSet*, &ziptcdataset, -1, PHP_IPTCDATASET_RES_NAME, le_iptcdataset); iptc_dataset_set_data (iptcdataset, data, datalen, IPTC_DONT_VALIDATE); RETURN_TRUE; } PHP_FUNCTION(iptc_data_add_dataset) { IptcData *iptcdata; IptcDataSet *iptcdataset; zval *ziptcdata, *ziptcdataset; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &ziptcdata, &ziptcdataset) == FAILURE) { RETURN_FALSE; } ZEND_FETCH_RESOURCE(iptcdata, IptcData*, &ziptcdata, -1, PHP_IPTCDATA_RES_NAME, le_iptcdata); ZEND_FETCH_RESOURCE(iptcdataset, IptcDataSet*, &ziptcdataset, -1, PHP_IPTCDATASET_RES_NAME, le_iptcdataset); if(iptc_data_add_dataset (iptcdata, iptcdataset)==-1){ RETURN_FALSE; } RETURN_TRUE; } PHP_FUNCTION(iptc_data_save) { IptcData *iptcdata; zval *ziptcdata; char *filename; int filenamelen; FILE *infile, *outfile; char *buf; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &ziptcdata, &filename, &filenamelen) == FAILURE) { RETURN_FALSE; } ZEND_FETCH_RESOURCE(iptcdata, IptcData*, &ziptcdata, -1, PHP_IPTCDATA_RES_NAME, le_iptcdata); unsigned char * iptc_buf = NULL; unsigned char outbuf[256*256]; char tmpfile[strlen(filename)+8]; int v, ps3_len, iptc_len; iptc_data_set_version (iptcdata, IPTC_IIM_VERSION); iptc_data_set_encoding_utf8 (iptcdata); iptc_data_sort (iptcdata); if (iptc_data_save (iptcdata, &iptc_buf, &iptc_len) < 0) { RETURN_FALSE; } ps3_len = iptc_jpeg_ps3_save_iptc (buf, ps3_len, iptc_buf, iptc_len, outbuf, sizeof(outbuf)); iptc_data_free_buf (iptcdata, iptc_buf); if (ps3_len < 0) { fprintf (stderr, "Failed to generate PS3 header\n"); RETURN_FALSE; } infile = fopen (filename, "r"); if (!infile) { fprintf (stderr, "Can't reopen input file\n"); RETURN_FALSE; } sprintf (tmpfile, "%s.%d", filename, getpid()); outfile = fopen (tmpfile, "w"); if (!outfile) { fprintf (stderr, "Can't open temporary file for writing\n"); RETURN_FALSE; } v = iptc_jpeg_save_with_ps3 (infile, outfile, outbuf, ps3_len); fclose (infile); fclose (outfile); if (v < 0) { unlink (tmpfile); fprintf (stderr, "Failed to save image\n"); RETURN_FALSE; } if (rename (tmpfile, filename) < 0) { fprintf (stderr, "Failed to save image\n"); unlink (tmpfile); RETURN_FALSE; } fprintf (stderr, "Image saved\n"); } PHP_FUNCTION(iptc_tag_get_title) { IptcData *iptcdata; zval *ziptcdata; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ziptcdata) == FAILURE) { RETURN_FALSE; } ZEND_FETCH_RESOURCE(iptcdata, IptcData*, &ziptcdata, -1, PHP_IPTCDATA_RES_NAME, le_iptcdata); // TODO // TODO // TODO RETURN_TRUE; } PHP_FUNCTION(iptc_data_from_jpeg) { char *filename; int filenamelen; IptcData *d; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filenamelen) == FAILURE) { RETURN_FALSE; } d = iptc_data_new_from_jpeg(filename); if (!d) { RETURN_FALSE; } array_init(return_value); int i; for(i=0; i<d->count; i++){ IptcDataSet * e = d->datasets[i]; char buf[256]; char *title = iptc_tag_get_title (e->record, e->tag); char *format = iptc_format_get_name (iptc_dataset_get_format (e)); zval *rowIptcDataSet; ALLOC_INIT_ZVAL(rowIptcDataSet); array_init(rowIptcDataSet); add_assoc_string(rowIptcDataSet,"title",title,TRUE); add_assoc_string(rowIptcDataSet,"format",format,TRUE); add_assoc_long(rowIptcDataSet, "tag", (long)e->tag); add_assoc_long(rowIptcDataSet, "size",(long)e->size); add_assoc_long(rowIptcDataSet, "record", (long)e->record); switch (iptc_dataset_get_format (e)) { case IPTC_FORMAT_BYTE: case IPTC_FORMAT_SHORT: case IPTC_FORMAT_LONG: add_assoc_long(rowIptcDataSet, "tag", (long)iptc_dataset_get_value (e)); break; case IPTC_FORMAT_BINARY: iptc_dataset_get_as_str (e, buf, sizeof(buf)); add_assoc_string(rowIptcDataSet,"value",buf,TRUE); break; default: iptc_dataset_get_data (e, buf, sizeof(buf)); add_assoc_string(rowIptcDataSet,"value",buf,TRUE); break; } //mysubarray->refcount = 2; add_next_index_zval(return_value, rowIptcDataSet); } } /* {{{ iptcdata_functions[] * * Every user visible function must have an entry in iptcdata_functions[]. */ zend_function_entry iptcdata_functions[] = { PHP_FE(iptc_data_from_jpeg, NULL) PHP_FE(iptc_data_new, NULL) PHP_FE(iptc_dataset_new, NULL) PHP_FE(iptc_data_new_from_jpeg, NULL) PHP_FE(iptc_dataset_set_tag, NULL) PHP_FE(iptc_dataset_set_data, NULL) PHP_FE(iptc_data_add_dataset, NULL) PHP_FE(iptc_data_save, NULL) {NULL, NULL, NULL} /* Must be the last line in iptcdata_functions[] */ }; /* }}} */ /* {{{ iptcdata_module_entry */ zend_module_entry iptcdata_module_entry = { #if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, #endif "iptcdata", iptcdata_functions, PHP_MINIT(iptcdata), PHP_MSHUTDOWN(iptcdata), PHP_RINIT(iptcdata), /* Replace with NULL if there's nothing to do at request start */ PHP_RSHUTDOWN(iptcdata), /* Replace with NULL if there's nothing to do at request end */ PHP_MINFO(iptcdata), #if ZEND_MODULE_API_NO >= 20010901 "0.1", /* Replace with version number for your extension */ #endif STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_IPTCDATA ZEND_GET_MODULE(iptcdata) #endif /* {{{ PHP_INI */ /* Remove comments and fill if you need to have entries in php.ini PHP_INI_BEGIN() STD_PHP_INI_ENTRY("iptcdata.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_iptcdata_globals, iptcdata_globals) STD_PHP_INI_ENTRY("iptcdata.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_iptcdata_globals, iptcdata_globals) PHP_INI_END() */ /* }}} */ /* {{{ php_iptcdata_init_globals */ /* Uncomment this function if you have INI entries static void php_iptcdata_init_globals(zend_iptcdata_globals *iptcdata_globals) { iptcdata_globals->global_value = 0; iptcdata_globals->global_string = NULL; } */ /* }}} */ /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(iptcdata) { /* If you have INI entries, uncomment these lines ZEND_INIT_MODULE_GLOBALS(iptcdata, php_iptcdata_init_globals, NULL); REGISTER_INI_ENTRIES(); */ le_iptcdata = zend_register_list_destructors_ex( NULL,NULL, PHP_IPTCDATA_RES_NAME, module_number); le_iptcdataset = zend_register_list_destructors_ex( NULL,NULL, PHP_IPTCDATASET_RES_NAME, module_number); return SUCCESS; } /* }}} */ /* {{{ PHP_MSHUTDOWN_FUNCTION */ PHP_MSHUTDOWN_FUNCTION(iptcdata) { /* uncomment this line if you have INI entries UNREGISTER_INI_ENTRIES(); */ return SUCCESS; } /* }}} */ /* Remove if there's nothing to do at request start */ /* {{{ PHP_RINIT_FUNCTION */ PHP_RINIT_FUNCTION(iptcdata) { return SUCCESS; } /* }}} */ /* Remove if there's nothing to do at request end */ /* {{{ PHP_RSHUTDOWN_FUNCTION */ PHP_RSHUTDOWN_FUNCTION(iptcdata) { return SUCCESS; } /* }}} */ /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(iptcdata) { php_info_print_table_start(); php_info_print_table_header(2, "iptcdata support", "enabled"); php_info_print_table_end(); /* Remove comments if you have entries in php.ini DISPLAY_INI_ENTRIES(); */ } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ http://cvs.php.net/viewvc.cgi/pecl/iptcdata/php_iptcdata.h?view=markup&rev=1.1 Index: pecl/iptcdata/php_iptcdata.h +++ pecl/iptcdata/php_iptcdata.h /* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2006 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: | +----------------------------------------------------------------------+ */ /* $Id: php_iptcdata.h,v 1.1 2006/11/14 22:24:20 crafics Exp $ */ #ifndef PHP_IPTCDATA_H #define PHP_IPTCDATA_H extern zend_module_entry iptcdata_module_entry; #define phpext_iptcdata_ptr &iptcdata_module_entry #ifdef PHP_WIN32 #define PHP_IPTCDATA_API __declspec(dllexport) #else #define PHP_IPTCDATA_API #endif #ifndef PHP_IPTCDATA_RES_NAME #define PHP_IPTCDATA_RES_NAME "IptcData Descriptor" #endif #ifndef PHP_IPTCDATASET_RES_NAME #define PHP_IPTCDATASET_RES_NAME "IptcDataSet Descriptor" #endif #ifdef ZTS #include "TSRM.h" #endif PHP_MINIT_FUNCTION(iptcdata); PHP_MSHUTDOWN_FUNCTION(iptcdata); PHP_RINIT_FUNCTION(iptcdata); PHP_RSHUTDOWN_FUNCTION(iptcdata); PHP_MINFO_FUNCTION(iptcdata); PHP_FUNCTION(confirm_iptcdata_compiled); /* For testing, remove later. */ /* Declare any global variables you may need between the BEGIN and END macros here: ZEND_BEGIN_MODULE_GLOBALS(iptcdata) long global_value; char *global_string; ZEND_END_MODULE_GLOBALS(iptcdata) */ /* In every utility function you add that needs to use variables in php_iptcdata_globals, call TSRMLS_FETCH(); after declaring other variables used by that function, or better yet, pass in TSRMLS_CC after the last function argument and declare your utility function with TSRMLS_DC after the last declared argument. Always refer to the globals in your function as IPTCDATA_G(variable). You are encouraged to rename these macros something shorter, see examples in any other php module directory. */ #ifdef ZTS #define IPTCDATA_G(v) TSRMG(iptcdata_globals_id, zend_iptcdata_globals *, v) #else #define IPTCDATA_G(v) (iptcdata_globals.v) #endif #endif /* PHP_IPTCDATA_H */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */
http://cvs.php.net/viewvc.cgi/pecl/iptcdata/config.m4?view=markup&rev=1.1 Index: pecl/iptcdata/config.m4 +++ pecl/iptcdata/config.m4 dnl $Id: config.m4,v 1.1 2006/11/14 22:24:20 crafics Exp $ dnl config.m4 for extension iptcdata PHP_ARG_WITH(iptcdata, for iptcdata support, [ --with-iptcdata Include iptcdata support]) if test "$PHP_IPTCDATA" != "no"; then SEARCH_PATH="/usr/local /usr" # you might want to change this SEARCH_FOR="/include/libiptcdata/iptc-data.h" # you most likely want to change this if test -r $PHP_IPTCDATA/$SEARCH_FOR; then # path given as parameter IPTCDATA_DIR=$PHP_IPTCDATA else # search default path list AC_MSG_CHECKING([for iptcdata files in default path]) for i in $SEARCH_PATH ; do if test -r $i/$SEARCH_FOR; then IPTCDATA_DIR=$i AC_MSG_RESULT(found in $i) fi done fi if test -z "$IPTCDATA_DIR"; then AC_MSG_RESULT([not found]) AC_MSG_ERROR([Please reinstall the iptcdata distribution]) fi PHP_ADD_INCLUDE($IPTCDATA_DIR/include) PHP_ADD_LIBRARY_WITH_PATH(iptcdata, $PHP_IPTCDATA_DIR/lib, IPTCDATA_SHARED_LIBADD) AC_CHECK_LIB(iptcdata, iptc_data_new_from_jpeg, [ AC_DEFINE(HAVE_IPTCDATALIB,1,[ ]) ], [ AC_MSG_ERROR(iptcdata library not found or wrong version) ],) PHP_SUBST(IPTCDATA_SHARED_LIBADD) PHP_NEW_EXTENSION(iptcdata, iptcdata.c, $ext_shared) fi http://cvs.php.net/viewvc.cgi/pecl/iptcdata/iptcdata.c?view=markup&rev=1.1 Index: pecl/iptcdata/iptcdata.c +++ pecl/iptcdata/iptcdata.c /* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2006 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: | +----------------------------------------------------------------------+ */ /* $Id: iptcdata.c,v 1.1 2006/11/14 22:24:20 crafics Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_iptcdata.h" #include "libiptcdata/iptc-data.h" #include "libiptcdata/iptc-dataset.h" #include "libiptcdata/iptc-jpeg.h" #include "libiptcdata/iptc-log.h" #include "libiptcdata/iptc-mem.h" #include "libiptcdata/iptc-tag.h" #include "libiptcdata/iptc-utils.h" #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif IptcRecord record; IptcTag tag; /* If you declare any globals in php_iptcdata.h uncomment this: ZEND_DECLARE_MODULE_GLOBALS(iptcdata) */ /* True global resources - no need for thread safety here */ static int le_iptcdata; static int le_iptcdataset; PHP_FUNCTION(iptc_data_new) { IptcData *d; d = iptc_data_new (); if(!d){ RETURN_FALSE; } ZEND_REGISTER_RESOURCE(return_value, d, le_iptcdata); } PHP_FUNCTION(iptc_data_new_from_jpeg) { char *filename; int filenamelen; IptcData *d; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filenamelen) == FAILURE) { RETURN_FALSE; } d = iptc_data_new_from_jpeg(filename); if (!d) { RETURN_FALSE; } ZEND_REGISTER_RESOURCE(return_value, d, le_iptcdata); } PHP_FUNCTION(iptc_dataset_new) { IptcDataSet *ds; ds = iptc_dataset_new (); if(!ds){ RETURN_FALSE; } ZEND_REGISTER_RESOURCE(return_value, ds, le_iptcdataset); } PHP_FUNCTION(iptc_dataset_set_tag) { IptcDataSet *iptcdataset; zval *ziptcdataset; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ziptcdataset) == FAILURE) { RETURN_FALSE; } ZEND_FETCH_RESOURCE(iptcdataset, IptcDataSet*, &ziptcdataset, -1, PHP_IPTCDATASET_RES_NAME, le_iptcdataset); iptc_dataset_set_tag (iptcdataset, record, tag); RETURN_TRUE; } PHP_FUNCTION(iptc_dataset_set_data) { IptcDataSet *iptcdataset; zval *ziptcdataset; char *data; int datalen; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &ziptcdataset, &data, &datalen) == FAILURE) { RETURN_FALSE; } ZEND_FETCH_RESOURCE(iptcdataset, IptcDataSet*, &ziptcdataset, -1, PHP_IPTCDATASET_RES_NAME, le_iptcdataset); iptc_dataset_set_data (iptcdataset, data, datalen, IPTC_DONT_VALIDATE); RETURN_TRUE; } PHP_FUNCTION(iptc_data_add_dataset) { IptcData *iptcdata; IptcDataSet *iptcdataset; zval *ziptcdata, *ziptcdataset; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &ziptcdata, &ziptcdataset) == FAILURE) { RETURN_FALSE; } ZEND_FETCH_RESOURCE(iptcdata, IptcData*, &ziptcdata, -1, PHP_IPTCDATA_RES_NAME, le_iptcdata); ZEND_FETCH_RESOURCE(iptcdataset, IptcDataSet*, &ziptcdataset, -1, PHP_IPTCDATASET_RES_NAME, le_iptcdataset); if(iptc_data_add_dataset (iptcdata, iptcdataset)==-1){ RETURN_FALSE; } RETURN_TRUE; } PHP_FUNCTION(iptc_data_save) { IptcData *iptcdata; zval *ziptcdata; char *filename; int filenamelen; FILE *infile, *outfile; char *buf; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &ziptcdata, &filename, &filenamelen) == FAILURE) { RETURN_FALSE; } ZEND_FETCH_RESOURCE(iptcdata, IptcData*, &ziptcdata, -1, PHP_IPTCDATA_RES_NAME, le_iptcdata); unsigned char * iptc_buf = NULL; unsigned char outbuf[256*256]; char tmpfile[strlen(filename)+8]; int v, ps3_len, iptc_len; iptc_data_set_version (iptcdata, IPTC_IIM_VERSION); iptc_data_set_encoding_utf8 (iptcdata); iptc_data_sort (iptcdata); if (iptc_data_save (iptcdata, &iptc_buf, &iptc_len) < 0) { RETURN_FALSE; } ps3_len = iptc_jpeg_ps3_save_iptc (buf, ps3_len, iptc_buf, iptc_len, outbuf, sizeof(outbuf)); iptc_data_free_buf (iptcdata, iptc_buf); if (ps3_len < 0) { fprintf (stderr, "Failed to generate PS3 header\n"); RETURN_FALSE; } infile = fopen (filename, "r"); if (!infile) { fprintf (stderr, "Can't reopen input file\n"); RETURN_FALSE; } sprintf (tmpfile, "%s.%d", filename, getpid()); outfile = fopen (tmpfile, "w"); if (!outfile) { fprintf (stderr, "Can't open temporary file for writing\n"); RETURN_FALSE; } v = iptc_jpeg_save_with_ps3 (infile, outfile, outbuf, ps3_len); fclose (infile); fclose (outfile); if (v < 0) { unlink (tmpfile); fprintf (stderr, "Failed to save image\n"); RETURN_FALSE; } if (rename (tmpfile, filename) < 0) { fprintf (stderr, "Failed to save image\n"); unlink (tmpfile); RETURN_FALSE; } fprintf (stderr, "Image saved\n"); } PHP_FUNCTION(iptc_tag_get_title) { IptcData *iptcdata; zval *ziptcdata; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ziptcdata) == FAILURE) { RETURN_FALSE; } ZEND_FETCH_RESOURCE(iptcdata, IptcData*, &ziptcdata, -1, PHP_IPTCDATA_RES_NAME, le_iptcdata); // TODO // TODO // TODO RETURN_TRUE; } PHP_FUNCTION(iptc_data_from_jpeg) { char *filename; int filenamelen; IptcData *d; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filenamelen) == FAILURE) { RETURN_FALSE; } d = iptc_data_new_from_jpeg(filename); if (!d) { RETURN_FALSE; } array_init(return_value); int i; for(i=0; i<d->count; i++){ IptcDataSet * e = d->datasets[i]; char buf[256]; char *title = iptc_tag_get_title (e->record, e->tag); char *format = iptc_format_get_name (iptc_dataset_get_format (e)); zval *rowIptcDataSet; ALLOC_INIT_ZVAL(rowIptcDataSet); array_init(rowIptcDataSet); add_assoc_string(rowIptcDataSet,"title",title,TRUE); add_assoc_string(rowIptcDataSet,"format",format,TRUE); add_assoc_long(rowIptcDataSet, "tag", (long)e->tag); add_assoc_long(rowIptcDataSet, "size",(long)e->size); add_assoc_long(rowIptcDataSet, "record", (long)e->record); switch (iptc_dataset_get_format (e)) { case IPTC_FORMAT_BYTE: case IPTC_FORMAT_SHORT: case IPTC_FORMAT_LONG: add_assoc_long(rowIptcDataSet, "tag", (long)iptc_dataset_get_value (e)); break; case IPTC_FORMAT_BINARY: iptc_dataset_get_as_str (e, buf, sizeof(buf)); add_assoc_string(rowIptcDataSet,"value",buf,TRUE); break; default: iptc_dataset_get_data (e, buf, sizeof(buf)); add_assoc_string(rowIptcDataSet,"value",buf,TRUE); break; } //mysubarray->refcount = 2; add_next_index_zval(return_value, rowIptcDataSet); } } /* {{{ iptcdata_functions[] * * Every user visible function must have an entry in iptcdata_functions[]. */ zend_function_entry iptcdata_functions[] = { PHP_FE(iptc_data_from_jpeg, NULL) PHP_FE(iptc_data_new, NULL) PHP_FE(iptc_dataset_new, NULL) PHP_FE(iptc_data_new_from_jpeg, NULL) PHP_FE(iptc_dataset_set_tag, NULL) PHP_FE(iptc_dataset_set_data, NULL) PHP_FE(iptc_data_add_dataset, NULL) PHP_FE(iptc_data_save, NULL) {NULL, NULL, NULL} /* Must be the last line in iptcdata_functions[] */ }; /* }}} */ /* {{{ iptcdata_module_entry */ zend_module_entry iptcdata_module_entry = { #if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, #endif "iptcdata", iptcdata_functions, PHP_MINIT(iptcdata), PHP_MSHUTDOWN(iptcdata), PHP_RINIT(iptcdata), /* Replace with NULL if there's nothing to do at request start */ PHP_RSHUTDOWN(iptcdata), /* Replace with NULL if there's nothing to do at request end */ PHP_MINFO(iptcdata), #if ZEND_MODULE_API_NO >= 20010901 "0.1", /* Replace with version number for your extension */ #endif STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_IPTCDATA ZEND_GET_MODULE(iptcdata) #endif /* {{{ PHP_INI */ /* Remove comments and fill if you need to have entries in php.ini PHP_INI_BEGIN() STD_PHP_INI_ENTRY("iptcdata.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_iptcdata_globals, iptcdata_globals) STD_PHP_INI_ENTRY("iptcdata.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_iptcdata_globals, iptcdata_globals) PHP_INI_END() */ /* }}} */ /* {{{ php_iptcdata_init_globals */ /* Uncomment this function if you have INI entries static void php_iptcdata_init_globals(zend_iptcdata_globals *iptcdata_globals) { iptcdata_globals->global_value = 0; iptcdata_globals->global_string = NULL; } */ /* }}} */ /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(iptcdata) { /* If you have INI entries, uncomment these lines ZEND_INIT_MODULE_GLOBALS(iptcdata, php_iptcdata_init_globals, NULL); REGISTER_INI_ENTRIES(); */ le_iptcdata = zend_register_list_destructors_ex( NULL,NULL, PHP_IPTCDATA_RES_NAME, module_number); le_iptcdataset = zend_register_list_destructors_ex( NULL,NULL, PHP_IPTCDATASET_RES_NAME, module_number); return SUCCESS; } /* }}} */ /* {{{ PHP_MSHUTDOWN_FUNCTION */ PHP_MSHUTDOWN_FUNCTION(iptcdata) { /* uncomment this line if you have INI entries UNREGISTER_INI_ENTRIES(); */ return SUCCESS; } /* }}} */ /* Remove if there's nothing to do at request start */ /* {{{ PHP_RINIT_FUNCTION */ PHP_RINIT_FUNCTION(iptcdata) { return SUCCESS; } /* }}} */ /* Remove if there's nothing to do at request end */ /* {{{ PHP_RSHUTDOWN_FUNCTION */ PHP_RSHUTDOWN_FUNCTION(iptcdata) { return SUCCESS; } /* }}} */ /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(iptcdata) { php_info_print_table_start(); php_info_print_table_header(2, "iptcdata support", "enabled"); php_info_print_table_end(); /* Remove comments if you have entries in php.ini DISPLAY_INI_ENTRIES(); */ } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ http://cvs.php.net/viewvc.cgi/pecl/iptcdata/php_iptcdata.h?view=markup&rev=1.1 Index: pecl/iptcdata/php_iptcdata.h +++ pecl/iptcdata/php_iptcdata.h /* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2006 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: | +----------------------------------------------------------------------+ */ /* $Id: php_iptcdata.h,v 1.1 2006/11/14 22:24:20 crafics Exp $ */ #ifndef PHP_IPTCDATA_H #define PHP_IPTCDATA_H extern zend_module_entry iptcdata_module_entry; #define phpext_iptcdata_ptr &iptcdata_module_entry #ifdef PHP_WIN32 #define PHP_IPTCDATA_API __declspec(dllexport) #else #define PHP_IPTCDATA_API #endif #ifndef PHP_IPTCDATA_RES_NAME #define PHP_IPTCDATA_RES_NAME "IptcData Descriptor" #endif #ifndef PHP_IPTCDATASET_RES_NAME #define PHP_IPTCDATASET_RES_NAME "IptcDataSet Descriptor" #endif #ifdef ZTS #include "TSRM.h" #endif PHP_MINIT_FUNCTION(iptcdata); PHP_MSHUTDOWN_FUNCTION(iptcdata); PHP_RINIT_FUNCTION(iptcdata); PHP_RSHUTDOWN_FUNCTION(iptcdata); PHP_MINFO_FUNCTION(iptcdata); PHP_FUNCTION(confirm_iptcdata_compiled); /* For testing, remove later. */ /* Declare any global variables you may need between the BEGIN and END macros here: ZEND_BEGIN_MODULE_GLOBALS(iptcdata) long global_value; char *global_string; ZEND_END_MODULE_GLOBALS(iptcdata) */ /* In every utility function you add that needs to use variables in php_iptcdata_globals, call TSRMLS_FETCH(); after declaring other variables used by that function, or better yet, pass in TSRMLS_CC after the last function argument and declare your utility function with TSRMLS_DC after the last declared argument. Always refer to the globals in your function as IPTCDATA_G(variable). You are encouraged to rename these macros something shorter, see examples in any other php module directory. */ #ifdef ZTS #define IPTCDATA_G(v) TSRMG(iptcdata_globals_id, zend_iptcdata_globals *, v) #else #define IPTCDATA_G(v) (iptcdata_globals.v) #endif #endif /* PHP_IPTCDATA_H */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */