jhead.c package with the author's consent. The main changes have been
to eliminate all the global variables to make it thread safe and to wrap
it in the PHP 4 API.
+
+ Aug.3 2001 - Added support for multiple M_COM entries - Rasmus
The original header from the jhead.c file was:
#define FALSE 0
#endif
+#define EXIF_MAX_COMMENTS 12
/* {{{ structs
This structure stores Exif header image elements in a simple manner
float ApertureFNumber;
float Distance;
float CCDWidth;
- char Comments[200];
+ char *Comments[EXIF_MAX_COMMENTS];
+ int numComments;
double FocalplaneXRes;
double FocalplaneUnits;
int ExifImageWidth;
int nch;
int a;
+ if(ImageInfo->numComments == EXIF_MAX_COMMENTS) return;
+
nch = 0;
if (length > 200) length = 200; /* Truncate if it won't fit in our structure. */
Comment[nch] = '\0'; /* Null terminate */
- /*
- if (ShowTags) {
- printf("COM marker comment: %s\n",Comment);
- }
- */
-
- strcpy(ImageInfo->Comments,Comment);
+ a = ImageInfo->numComments;
+
+ (ImageInfo->Comments)[a] = emalloc(nch+1);
+ strcpy(ImageInfo->Comments[a],Comment);
+ (ImageInfo->numComments)++;
}
/* }}} */
/* Copy the comment */
if (memcmp(ValuePtr, "ASCII",5) == 0) {
for (a=5;a<10;a++) {
- int c;
+ int c; int l;
c = (ValuePtr)[a];
if (c != '\0' && c != ' ') {
- strlcpy(ImageInfo->Comments, a+ValuePtr, sizeof(ImageInfo->Comments));
+ l = strlen(a+ValuePtr)+1;
+ l = (l<200)?l:201;
+ (ImageInfo->Comments)[ImageInfo->numComments] = emalloc(l);
+ strlcpy((ImageInfo->Comments)[ImageInfo->numComments], a+ValuePtr, l);
+ ImageInfo->numComments++;
break;
}
}
} else {
- strlcpy(ImageInfo->Comments, ValuePtr, sizeof(ImageInfo->Comments));
+ int l;
+
+ l = strlen(ValuePtr)+1;
+ l = (l<200)?l:201;
+ (ImageInfo->Comments)[ImageInfo->numComments] = emalloc(l);
+ strlcpy((ImageInfo->Comments)[ImageInfo->numComments], ValuePtr, l);
}
break;
return FALSE;
case M_COM: /* Comment section */
+ /*
if (HaveCom) {
(*SectionsRead) -= 1;
efree(Sections[*SectionsRead].Data);
process_COM(ImageInfo, Data, itemlen);
HaveCom = TRUE;
}
+ */
+ process_COM(ImageInfo, Data, itemlen);
break;
case M_EXIF:
Reads the EXIF header data from a JPEG file */
PHP_FUNCTION(read_exif_data)
{
- pval **p_name, **p_readall;
+ pval **p_name, **p_readall, *tmpi;
int ac = ZEND_NUM_ARGS(), ret, readall=1;
ImageInfoType ImageInfo;
char tmp[64];
if (ImageInfo.Software[0]) {
add_assoc_string(return_value,"Software",ImageInfo.Software,1);
}
- if(ImageInfo.Comments[0]) {
- add_assoc_string(return_value,"Comments",ImageInfo.Comments,1);
+ if(ImageInfo.numComments) {
+ if(ImageInfo.numComments==1) {
+ add_assoc_string(return_value,"Comments",(ImageInfo.Comments)[0],0);
+ } else {
+ int i;
+
+ MAKE_STD_ZVAL(tmpi);
+ array_init(tmpi);
+ for(i=0; i<ImageInfo.numComments; i++) {
+ add_index_string(tmpi, i, (ImageInfo.Comments)[i], 0);
+ }
+ zend_hash_update(return_value->value.ht, "Comments", 9, &tmpi, sizeof(zval *), NULL);
+ }
}
if(ImageInfo.ThumbnailSize && ImageInfo.Thumbnail) {
add_assoc_stringl(return_value,"Thumbnail",ImageInfo.Thumbnail,ImageInfo.ThumbnailSize,1);