summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/exif/exif.c165
-rw-r--r--ext/exif/test.txt187
-rw-r--r--ext/exif/tests/001.phpt2
3 files changed, 249 insertions, 105 deletions
diff --git a/ext/exif/exif.c b/ext/exif/exif.c
index f6726d5318..07e9af2291 100644
--- a/ext/exif/exif.c
+++ b/ext/exif/exif.c
@@ -67,7 +67,7 @@
* while extending the module as it shows if you are at the right position.
* You are always considered to have a copy of TIFF6.0 and EXIF2.10 standard.
*/
-#define EXIF_DEBUG
+#undef EXIF_DEBUG
#include "php_exif.h"
#include <math.h>
@@ -130,8 +130,8 @@ PHP_MINIT_FUNCTION(exif)
REGISTER_LONG_CONSTANT("IMAGETYPE_TIFF_MM", IMAGE_FILETYPE_TIFF_MM, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("IMAGETYPE_JPC", IMAGE_FILETYPE_JPC, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("IMAGETYPE_JP2", IMAGE_FILETYPE_JP2, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("IMAGETYPE_JB2", IMAGE_FILETYPE_JB2, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("IMAGETYPE_JPX", IMAGE_FILETYPE_JPX, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("IMAGETYPE_JB2", IMAGE_FILETYPE_JB2, CONST_CS | CONST_PERSISTENT);
return SUCCESS;
}
/* }}} */
@@ -907,6 +907,9 @@ typedef struct {
char *UserComment;
char *UserCommentEncoding;
+ char *Copyright;
+ char *CopyrightPhotographer;
+ char *CopyrightEditor;
thumbnail_data Thumbnail;
/* other */
@@ -1140,7 +1143,7 @@ void exif_iif_add_tag( image_info_type *image_info, int section_index, char *nam
/* }}} */
/* {{{ exif_iif_add_int
- Add a tag from IFD to image_info
+ Add an int value to image_info
*/
void exif_iif_add_int( image_info_type *image_info, int section_index, char *name, int value)
{
@@ -1169,6 +1172,49 @@ void exif_iif_add_int( image_info_type *image_info, int section_index, char *nam
}
/* }}} */
+/* {{{ exif_iif_add_str
+ Add a string value to image_info MUST BE NUL TERMINATED
+*/
+void exif_iif_add_str( image_info_type *image_info, int section_index, char *name, char *value, ...)
+{
+ image_info_data *info_data;
+ image_info_data *list;
+ char tmp[1024];
+ va_list arglist;
+
+ va_start( arglist, value );
+ if ( value) vsnprintf( tmp, sizeof(tmp), value, arglist);
+ va_end( arglist);
+
+ if ( value) {
+
+ list = erealloc(image_info->info_list[section_index].list,(image_info->info_list[section_index].count+1)*sizeof(image_info_data));
+ if ( !list) {
+ EXIF_ERRLOG_EALLOC
+ return;
+ }
+ image_info->info_list[section_index].list = list;
+
+ info_data = &image_info->info_list[section_index].list[image_info->info_list[section_index].count];
+ info_data->tag = TAG_NONE;
+ info_data->format = TAG_FMT_STRING;
+ info_data->length = 1;
+ info_data->name = estrdup(name);
+ if ( !info_data->name) {
+ EXIF_ERRLOG_EALLOC
+ return;
+ }
+ info_data->value.s = estrdup(tmp);
+ if ( !info_data->value.s) {
+ EXIF_ERRLOG_EALLOC
+ return;
+ }
+ image_info->sections_found |= 1<<section_index;
+ image_info->info_list[section_index].count++;
+ }
+}
+/* }}} */
+
/* {{{ exif_iif_free
Free memory allocated for image_info
*/
@@ -1754,7 +1800,6 @@ static void exif_thumbnail_build(image_info_type *ImageInfo) {
new_size += byte_count;
}
}
- php_error(E_NOTICE,"thumbnail: writing with value offset: 0x%04X", new_value);
new_move = new_size;
new_data = erealloc(ImageInfo->Thumbnail.data,ImageInfo->Thumbnail.size+new_size);
if (!ImageInfo->Thumbnail.data) {
@@ -1774,7 +1819,6 @@ static void exif_thumbnail_build(image_info_type *ImageInfo) {
memmove( new_data, "II\x2a\x00\x08\x00\x00\x00", 8);
}
new_data += 8;
- php_error(E_NOTICE,"thumbnail: writing directory size");
php_ifd_set16u( new_data, info_list->count, ImageInfo->motorola_intel);
new_data += 2;
for (i=0; i<info_list->count; i++) {
@@ -1809,7 +1853,6 @@ static void exif_thumbnail_build(image_info_type *ImageInfo) {
#endif
memmove( ImageInfo->Thumbnail.data+new_value, value_ptr, byte_count);
new_value += byte_count;
- php_error(E_NOTICE,"thumbnail: components: \n%s\n", exif_char_dump(value_ptr,byte_count,1));
}
efree(value_ptr);
}
@@ -1852,10 +1895,9 @@ static void exif_thumbnail_extract(image_info_type *ImageInfo, char *offset, siz
}
/* }}} */
-/* {{{ exif_process_string_raw
- * Copy a string in Exif header to a character string returns length of allocated buffer if any. */
-#ifdef EXIF_DEBUG
-static int exif_process_string_raw(char **result,char *value,size_t byte_count) {
+/* {{{ exif_process_undefined
+ * Copy a string/buffer in Exif header to a character string and return length of allocated buffer if any. */
+static int exif_process_undefined(char **result,char *value,size_t byte_count) {
/* we cannot use strlcpy - here the problem is that we have to copy NUL
* chars up to byte_count, we also have to add a single NUL character to
* force end of string.
@@ -1871,11 +1913,11 @@ static int exif_process_string_raw(char **result,char *value,size_t byte_count)
}
return 0;
}
-#endif
/* }}} */
/* {{{ exif_process_string
- * Copy a string in Exif header to a character string returns length of allocated buffer if any. */
+ * Copy a string in Exif header to a character string and return length of allocated buffer if any.
+ * In contrast to exif_process_undefined this function does allways return a string buffer */
static int exif_process_string(char **result,char *value,size_t byte_count) {
/* we cannot use strlcpy - here the problem is that we cannot use strlen to
* determin length of string and we cannot use strlcpy with len=byte_count+1
@@ -1885,14 +1927,14 @@ static int exif_process_string(char **result,char *value,size_t byte_count) {
* estrdup would sometimes allocate more memory and does not return length
*/
if ((byte_count=php_strnlen(value,byte_count)) > 0) {
- (*result) = estrndup(value,byte_count);
- if ( !*result) {
- EXIF_ERRLOG_EALLOC
- return 0;
- }
- return byte_count+1;
+ return exif_process_undefined(result,value,byte_count);
}
- return 0;
+ (*result) = estrndup("",1); /* force empty string */
+ if ( !*result) {
+ EXIF_ERRLOG_EALLOC
+ return 0;
+ }
+ return byte_count+1;
}
/* }}} */
@@ -2077,14 +2119,26 @@ static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, cha
} else {
switch(tag) {
case TAG_COPYRIGHT:
+ /* check for "<photographer> NUL <editor> NUL" */
if (byte_count>1 && (l=php_strnlen(value_ptr,byte_count)) > 0) {
if ( l<byte_count-1) {
/* When there are any characters after the first NUL */
- exif_iif_add_tag( ImageInfo, SECTION_COMPUTED, "Copyright.Photographer", TAG_COPYRIGHT, TAG_FMT_STRING, l, value_ptr);
- exif_iif_add_tag( ImageInfo, SECTION_COMPUTED, "Copyright.Editor", TAG_COPYRIGHT, TAG_FMT_STRING, byte_count-l-1, value_ptr+l+1);
+ ImageInfo->CopyrightPhotographer = estrdup( value_ptr);
+ ImageInfo->CopyrightEditor = estrdup( value_ptr);
+ ImageInfo->Copyright = emalloc(byte_count+3);
+ if ( !ImageInfo->Copyright) {
+ EXIF_ERRLOG_EALLOC
+ } else {
+ sprintf( ImageInfo->Copyright, "%s, %s", value_ptr, value_ptr+l+1);
+ }
+ /* format = TAG_FMT_UNDEFINED; this musn't be ASCII */
+ /* but we are not supposed to change this */
+ /* keep in mind that image_info does not store editor value */
#ifdef EXIF_DEBUG
php_error(E_NOTICE,"added copyrights: %s, %s", value_ptr, value_ptr+l+1);
#endif
+ } else {
+ ImageInfo->Copyright = estrdup(value_ptr);
}
}
break;
@@ -2509,6 +2563,10 @@ static int exif_scan_thumbnail(image_info_type *ImageInfo)
size_t length=2, pos=0;
jpeg_sof_info sof_info;
+ if ( !data)
+ {
+ return FALSE; /* nothing to do here */
+ }
if ( memcmp(data,"\xFF\xD8\xFF",3))
{
if ( !ImageInfo->Thumbnail.width && !ImageInfo->Thumbnail.height)
@@ -2853,10 +2911,13 @@ int exif_discard_imageinfo(image_info_type *ImageInfo)
{
int i;
- if (ImageInfo->FileName) efree(ImageInfo->FileName);
- if (ImageInfo->UserComment) efree(ImageInfo->UserComment);
- if (ImageInfo->UserCommentEncoding) efree(ImageInfo->UserCommentEncoding);
- if (ImageInfo->Thumbnail.data) efree(ImageInfo->Thumbnail.data);
+ if (ImageInfo->FileName) efree(ImageInfo->FileName);
+ if (ImageInfo->UserComment) efree(ImageInfo->UserComment);
+ if (ImageInfo->UserCommentEncoding) efree(ImageInfo->UserCommentEncoding);
+ if (ImageInfo->Copyright) efree(ImageInfo->Copyright);
+ if (ImageInfo->CopyrightPhotographer) efree(ImageInfo->CopyrightPhotographer);
+ if (ImageInfo->CopyrightEditor) efree(ImageInfo->CopyrightEditor);
+ if (ImageInfo->Thumbnail.data) efree(ImageInfo->Thumbnail.data);
for (i=0; i<SECTION_COUNT; i++) {
exif_iif_free( ImageInfo, i);
}
@@ -2911,7 +2972,7 @@ int exif_read_file(image_info_type *ImageInfo, char *FileName, int read_thumbnai
PHP_FUNCTION(exif_read_data)
{
pval **p_name, **p_sections_needed, **p_sub_arrays, **p_read_thumbnail, **p_read_all;
- int i, len, ac = ZEND_NUM_ARGS(), ret, sections_needed=0, sub_arrays=0, read_thumbnail=0, read_all=0;
+ int i, ac = ZEND_NUM_ARGS(), ret, sections_needed=0, sub_arrays=0, read_thumbnail=0, read_all=0;
image_info_type ImageInfo;
char tmp[64], *sections_str, *s;
@@ -2991,71 +3052,72 @@ PHP_FUNCTION(exif_read_data)
#endif
/* now we can add our information */
- exif_iif_add_tag( &ImageInfo, SECTION_FILE, "FileName", TAG_NONE, TAG_FMT_STRING, strlen(ImageInfo.FileName), ImageInfo.FileName);
+ exif_iif_add_str( &ImageInfo, SECTION_FILE, "FileName", ImageInfo.FileName);
exif_iif_add_int( &ImageInfo, SECTION_FILE, "FileDateTime", ImageInfo.FileDateTime);
exif_iif_add_int( &ImageInfo, SECTION_FILE, "FileSize", ImageInfo.FileSize);
exif_iif_add_int( &ImageInfo, SECTION_FILE, "FileType", ImageInfo.FileType);
- if ( sections_str) exif_iif_add_tag( &ImageInfo, SECTION_FILE, "SectionsFound", TAG_NONE, TAG_FMT_STRING, strlen(sections_str), sections_str);
+ exif_iif_add_str( &ImageInfo, SECTION_FILE, "SectionsFound", sections_str ? sections_str : "NONE");
#ifdef EXIF_DEBUG
php_error(E_NOTICE,"generate section COMPUTED");
#endif
if (ImageInfo.Width>0 && ImageInfo.Height>0) {
- sprintf(tmp, "width=\"%d\" height=\"%d\"", ImageInfo.Width, ImageInfo.Height);
- exif_iif_add_tag( &ImageInfo, SECTION_COMPUTED, "html", TAG_NONE, TAG_FMT_STRING, strlen(tmp), tmp);
+ exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "html", "width=\"%d\" height=\"%d\"", ImageInfo.Width, ImageInfo.Height);
exif_iif_add_int( &ImageInfo, SECTION_COMPUTED, "Height", ImageInfo.Height);
exif_iif_add_int( &ImageInfo, SECTION_COMPUTED, "Width", ImageInfo.Width);
}
exif_iif_add_int( &ImageInfo, SECTION_COMPUTED, "IsColor", ImageInfo.IsColor);
if (ImageInfo.FocalLength) {
- sprintf(tmp, "%4.1fmm", ImageInfo.FocalLength);
- exif_iif_add_tag( &ImageInfo, SECTION_COMPUTED, "FocalLength", TAG_NONE, TAG_FMT_STRING, strlen(tmp), tmp);
+ exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "FocalLength", "%4.1fmm", ImageInfo.FocalLength);
if(ImageInfo.CCDWidth) {
- sprintf(tmp, "%dmm", (int)(ImageInfo.FocalLength/ImageInfo.CCDWidth*35+0.5));
- exif_iif_add_tag( &ImageInfo, SECTION_COMPUTED, "35mmFocalLength", TAG_NONE, TAG_FMT_STRING, strlen(tmp), tmp);
+ exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "35mmFocalLength", "%dmm", (int)(ImageInfo.FocalLength/ImageInfo.CCDWidth*35+0.5));
}
}
if(ImageInfo.CCDWidth) {
- sprintf(tmp, "%dmm", (int)ImageInfo.CCDWidth);
- exif_iif_add_tag( &ImageInfo, SECTION_COMPUTED, "CCDWidth", TAG_NONE, TAG_FMT_STRING, strlen(tmp), tmp);
+ exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "CCDWidth", "%dmm", (int)ImageInfo.CCDWidth);
}
if(ImageInfo.ExposureTime>0) {
if(ImageInfo.ExposureTime <= 0.5) {
- sprintf(tmp, "%0.3f s (1/%d)", ImageInfo.ExposureTime, (int)(0.5 + 1/ImageInfo.ExposureTime));
+ exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "ExposureTime", "%0.3f s (1/%d)", ImageInfo.ExposureTime, (int)(0.5 + 1/ImageInfo.ExposureTime));
} else {
- sprintf(tmp, "%0.3f s", ImageInfo.ExposureTime);
+ exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "ExposureTime", "%0.3f s", ImageInfo.ExposureTime);
}
- exif_iif_add_tag( &ImageInfo, SECTION_COMPUTED, "ExposureTime", TAG_NONE, TAG_FMT_STRING, strlen(tmp), tmp);
}
if(ImageInfo.ApertureFNumber) {
- sprintf(tmp, "f/%.1f", ImageInfo.ApertureFNumber);
- exif_iif_add_tag( &ImageInfo, SECTION_COMPUTED, "ApertureFNumber", TAG_NONE, TAG_FMT_STRING, strlen(tmp), tmp);
+ exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "ApertureFNumber", "f/%.1f", ImageInfo.ApertureFNumber);
}
if(ImageInfo.Distance) {
if(ImageInfo.Distance<0) {
- sprintf(tmp,"%s","Infinite");
+ exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "FocusDistance", "Infinite");
} else {
- sprintf(tmp, "%0.2fm", ImageInfo.Distance);
+ exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "FocusDistance", "%0.2fm", ImageInfo.Distance);
}
- exif_iif_add_tag( &ImageInfo, SECTION_COMPUTED, "FocusDistance", TAG_NONE, TAG_FMT_STRING, strlen(tmp), tmp);
}
if (ImageInfo.UserComment) {
- exif_iif_add_tag( &ImageInfo, SECTION_COMPUTED, "UserComment", TAG_NONE, TAG_FMT_STRING, strlen(ImageInfo.UserComment), ImageInfo.UserComment);
- if ( ImageInfo.UserCommentEncoding && (len=strlen(ImageInfo.UserCommentEncoding))) {
- exif_iif_add_tag( &ImageInfo, SECTION_COMPUTED, "UserCommentEncoding", TAG_NONE, TAG_FMT_STRING, len, ImageInfo.UserCommentEncoding);
+ exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "UserComment", ImageInfo.UserComment);
+ if ( ImageInfo.UserCommentEncoding && strlen(ImageInfo.UserCommentEncoding)) {
+ exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "UserCommentEncoding", ImageInfo.UserCommentEncoding);
}
}
+ exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "Copyright", ImageInfo.Copyright);
+ exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "Copyright.Photographer", ImageInfo.CopyrightPhotographer);
+ exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "Copyright.Editor", ImageInfo.CopyrightEditor);
+
if ( ImageInfo.Thumbnail.size) {
if ( read_thumbnail) {
+ /* not exif_iif_add_str : this is a buffer */
exif_iif_add_tag( &ImageInfo, SECTION_THUMBNAIL, "THUMBNAIL", TAG_NONE, TAG_FMT_UNDEFINED, ImageInfo.Thumbnail.size, ImageInfo.Thumbnail.data);
}
if ( !ImageInfo.Thumbnail.width || !ImageInfo.Thumbnail.height) {
+ /* try to evaluate if thumbnail data is present */
exif_scan_thumbnail( &ImageInfo);
}
- exif_iif_add_int( &ImageInfo, SECTION_COMPUTED, "Thumbnail.Height", ImageInfo.Thumbnail.height);
- exif_iif_add_int( &ImageInfo, SECTION_COMPUTED, "Thumbnail.Width", ImageInfo.Thumbnail.width);
+ if ( ImageInfo.Thumbnail.width && ImageInfo.Thumbnail.height) {
+ exif_iif_add_int( &ImageInfo, SECTION_COMPUTED, "Thumbnail.Height", ImageInfo.Thumbnail.height);
+ exif_iif_add_int( &ImageInfo, SECTION_COMPUTED, "Thumbnail.Width", ImageInfo.Thumbnail.width);
+ }
}
if ( sections_str) efree(sections_str);
@@ -3133,7 +3195,10 @@ PHP_FUNCTION(exif_thumbnail)
ZVAL_STRINGL( return_value, ImageInfo.Thumbnail.data, ImageInfo.Thumbnail.size, 1);
if ( arg_c == 3)
{
- exif_scan_thumbnail( &ImageInfo);
+ if ( !ImageInfo.Thumbnail.width || !ImageInfo.Thumbnail.height)
+ {
+ exif_scan_thumbnail( &ImageInfo);
+ }
ZVAL_LONG( *p_width, ImageInfo.Thumbnail.width);
ZVAL_LONG( *p_height, ImageInfo.Thumbnail.height);
}
diff --git a/ext/exif/test.txt b/ext/exif/test.txt
index 5ada592a22..1c12b509e6 100644
--- a/ext/exif/test.txt
+++ b/ext/exif/test.txt
@@ -32,6 +32,11 @@ if ( $file) {
die();
}
+if ( !defined('IMAGETYPE_GIF')) define('IMAGETYPE_GIF',1);
+if ( !defined('IMAGETYPE_JPEG')) define('IMAGETYPE_JPEG',2);
+if ( !defined('IMAGETYPE_TIFF_II')) define('IMAGETYPE_TIFF_II',7);
+if ( !defined('IMAGETYPE_TIFF_MM')) define('IMAGETYPE_TIFF_MM',8);
+
$possible = array();
/****************************************************************************/
@@ -54,6 +59,8 @@ function error_msg() {
// private to function search_file()
function _search_file($root,&$possible,$path='') {
$sub = array();
+ $cnt = 0;
+ $type= false;
//error_log("search_file($root,$path)",0);
if ($dir = @opendir($root.$path.'/')) {
@@ -62,16 +69,26 @@ function _search_file($root,&$possible,$path='') {
//error_log("search_file($root$path):$type=$found",0);
switch( $type) {
case 'file':
- $pos = strpos($found,'.');
- if ( $pos !== false
- && ( strtolower(substr($found,$pos+1))=='jpg'
- || strtolower(substr($found,$pos+1))=='tif'
- || strtolower(substr($found,$pos+1))=='gif'
- )
- )
+ $pos = strrpos($found,'.');
+ if ( function_exists('exif_imagetype')) {
+ $type = exif_imagetype($root.$path.'/'.$found);
+ } else {
+ if ( $pos!==false) {
+ $type = GetImageSize($root.$path.'/'.$found);
+ if ( is_array($type)) {
+ $type = $type[2];
+ } else {
+ $type = false;
+ }
+ } else $type = false;
+ }
+ if ( $type!==false)
{
- $possible[] = $root.$path.'/'.$found;
+ $possible[] = array('file'=>$root.$path.'/'.$found, 'type'=>$type);
//error_log("search_file($root$path) add:$path/$found",0);
+ if ( ($cnt=count($possible)) % 100 == 0) {
+ error_log("exif test page - counting files: $cnt",0);
+ }
}
break;
case 'dir':
@@ -94,10 +111,12 @@ function _search_file($root,&$possible,$path='') {
// Searches for $file in document tree. The path is ignored.
//
function search_file() {
- global $argv;
+ global $argc, $argv;
$possible = array();
- if ( array_key_exists('SCRIPT_FILENAME',$_SERVER)) {
+ if ( $argc > 1) {
+ $path = $argv[1];
+ } else if ( array_key_exists('SCRIPT_FILENAME',$_SERVER)) {
$path = $_SERVER['SCRIPT_FILENAME'];
//error_log("SCRIPT_FILENAME($path)",0);
} else {
@@ -105,8 +124,10 @@ function search_file() {
//error_log("argv($path)",0);
}
if ( ($p=strpos($path,'?')) !== false) $path = substr($path,0,$p);
- if ( ($p=strrpos($path,'/')) < strlen($path)-1) $path = substr($path,0,$p);
+ if ( ($p=strrpos($path,'/')) /*< strlen($path)-1*/) $path = substr($path,0,$p);
+ error_log("exif test page - counting files in $path");
_search_file($path,$possible);
+ error_log("exif test page - counting files: ".count($possible)." done.",0);
return $possible;
}
@@ -115,10 +136,15 @@ function search_file() {
//
// Searches for $file in document tree. The path is ignored.
//
-function AddInfo($Name,$Value) {
+function AddInfo($Name,$Value,$highlight=0) {
if (is_array($Value)) $Value = 'Array: ('.join(',',$Value).')';
$Value = nl2br($Value);
- return "<tr><td>$Name</td><td>$Value&nbsp;</td></tr>\n";
+ if ( $highlight) {
+ $Name = "<th>$Name</th>";
+ } else {
+ $Name = "<td>$Name</td>";
+ }
+ return "<tr>$Name<td>$Value&nbsp;</td></tr>\n";
}
$possible = search_file();
@@ -151,7 +177,7 @@ ul {
</head>
<body>
<h1><?=$title ?></h1>
-<h2>(c) Marcus Boerger, 2002</h2>
+<h2>(c) Marcus B&ouml;rger, 2002</h2>
</p>
<p>
Images taken from <a href="http://www.exif.org">www.exif.org</a>,
@@ -222,62 +248,115 @@ if (function_exists('exif_tagname')) {
<h2>function exif_read_data for <?=count($possible)?> images</h2>
<?php
+$check_getimagesize = false;
+$check_exif_thumbnail = true;
+$check_exif_read_data = false;
+$fast_output = false;
if (function_exists('exif_read_data')) {
$num = 0;
- $tab1 = "<table border='1' cellspacing='0' cellpadding='3' summary='function results'>\n";
+ echo "<table border='1' cellspacing='0' cellpadding='3' summary='function results'>\n";
$tab2 = "";//"<table border='1' cellspacing='0' cellpadding='3' summary='EXIF information'>\n";
+ $types = array('','GIF','JPEG','PNG','SWF','PSD','BMP','TIFF_II','TIFF_MM','JPC','JP2','JPX','JB2');
foreach($possible as $idx => $file) {
- $num++;
+ $type = $file['type'];
+ $file = $file['file'];
+ if ( !((++$num)%100)) error_log("exif test page - checking files: $num",0);
$error = '';
- $len = 4;
- $tab1 .= "<tr><td rowspan='3' valign='top'>$num</td><th colspan='2'>$file</th></tr>\n";
- $size = GetImageSize($file);
- $error = error_msg();// clear message
- if ( $size === false) {
- $getimagesize = '<b style="color:red">GetImageSize returned false</b><br>'.$error;
- } else {
- $getimagesize = "[ $size[0], $size[1], $size[2], $size[3] ]";
+ $len = 2;
+ $rows = 1
+ + ($check_getimagesize ? 1 : 0)
+ + ($check_exif_thumbnail ? 1 : 0)
+ + ($check_exif_read_data ? 1 : 0);
+ if ( !$fast_output) echo "<tr><td rowspan='$rows' valign='top'>$num</td><th colspan='2'>$file</th></tr>\n";
+ if ($check_getimagesize) {
+ $len++;
+ $size = GetImageSize($file);
+ $error = error_msg();// clear message
+ if ( $size === false) {
+ $error = '<b style="color:red">GetImageSize returned false</b><br>'.$error;
+ $res_getimagesize = $error;
+ } else {
+ $res_getimagesize = '('.join($size,',').')';
+ }
+ if ( !$fast_output) echo AddInfo("GetImageSize",$error,1);
+ }
+ if ( $check_exif_thumbnail) {
+ $len++;
+ if ($type!=IMAGETYPE_JPEG) {// && $type!=IMAGETYPE_TIFF_II && $type!=IMAGETYPE_TIFF_MM) {
+ $error = "<b style='color: green'>filetype not supported: $types[$type]</b>";
+ $res_exif_thumbnail = $error;
+ } else {
+ $t_width = 0;
+ $t_height = 0;
+ $result = exif_thumbnail($file, $t_width, $t_height);
+ $error = error_msg();// clear message
+ if ( $result === false) {
+ $error = '<b style="color:red">exif_thumbnail returned false</b><br>'.$error;
+ if ( $t_width && $t_height) {
+ $error = "<b style='color:green'>$t_width x $t_height</b><br>$error";
+ }
+ $res_exif_thumbnail = $error;
+ } else {
+ $res_exif_thumbnail = $t_width . " x " . $t_height;
+ }
+ }
+ if ( !$fast_output) echo AddInfo("exif_thumbnail",$error,1);
}
- $tab1 .= AddInfo("GetImageSize",$error);
- /**/
- error_log("exif_read_data($file,'COMMENT,IFD0,EXIF,APP12', true);",0);
- $image = exif_read_data($file,'COMMENT,IFD0,EXIF,APP12',true);
- $error = error_msg();// clear message
- $tab1 .= AddInfo("exif_read_data",$error);
- error_log("exif_read_data($file,'COMMENT,IFD0,EXIF,APP12', true): $error",0);
- //error_log("exif_read_data($file)",0);
- $res = '';
- if ( $image === false) {
- $error = '<b style="color:red">exif_read_data returned false</b><br>'.$error;
- } else {
- // ah no!$error = error_msg(); // force o.k.
- foreach($image as $Name => $Value) {
- if ( $Name!='Thumbnail') {
- if ( is_array($Value)) {
- $len++;
- $res .= AddInfo($Name,'Array('.count($Value).')');
- foreach( $Value as $idx => $Entry) {
- if ($idx==='Thumbnail') $Entry = '&lt;data&gt;';
- $len++;
- $res .= AddInfo($Name.':'.$idx,$Entry);
+ if ($check_exif_read_data) {
+ $len++;
+ if ($type!=IMAGETYPE_JPEG && $type!=IMAGETYPE_TIFF_II && $type!=IMAGETYPE_TIFF_MM) {
+ $res_exif_read_data = "<b style='color: green'>filetype not supported: $types[$type]</b>";
+ if ( !$fast_output) echo AddInfo("exif_read_data",$res_exif_read_data);
+ $res = '';
+ } else {
+ $image = exif_read_data($file,'COMMENT,IFD0,EXIF,APP12',true);
+ $error = error_msg();// clear message
+ if ( !$fast_output) echo AddInfo("exif_read_data",$error,1);
+ $res = '';
+ if ( $image === false) {
+ $res_exif_read_data = "<b style='color:red'>exif_read_data returned false</b><br>$error";
+ } else {
+ $res_exif_read_data = $error;
+ // ah no!$error = error_msg(); // force o.k.
+ foreach($image as $Name => $Value) {
+ if ( $Name!='Thumbnail') {
+ if ( is_array($Value)) {
+ $len++;
+ $res .= AddInfo($Name,'Array('.count($Value).')');
+ foreach( $Value as $idx => $Entry) {
+ if ($idx==='Thumbnail') $Entry = '&lt;data&gt;';
+ $len++;
+ $res .= AddInfo($Name.':'.$idx,$Entry);
+ }
+ } else {
+ $len++;
+ $res .= AddInfo($Name,$Value);
+ }
}
- } else {
- $len++;
- $res .= AddInfo($Name,$Value);
}
}
}
}
$tab2 .= "<tr><td rowspan='$len' valign='top'>$num</td></tr>\n";
$tab2 .= "<tr><th colspan='2'>$file</th></tr>\n";
- $tab2 .= "<tr><td><b>GetImageSize</b></td><td>$getimagesize</td></tr>\n";
- $tab2 .= "<tr><td><b>exif_read_data</b></td><td>$error</td></tr>\n";
+ if ($check_getimagesize) {
+ $tab2 .= "<tr><th>GetImageSize</th><td>$res_getimagesize</td></tr>\n";
+ }
+ if ($check_exif_thumbnail) {
+ $tab2 .= "<tr><th>exif_thumbnail</th><td>$res_exif_thumbnail</td></tr>\n";
+ }
+ if ($check_exif_read_data) {
+ $tab2 .= "<tr><th>exif_read_data</th><td>$res_exif_read_data</td></tr>\n";
$tab2 .= $res;
+ }
+ if ( $fast_output) {
+ echo $tab2;
+ $tab2 = '';
+ }
}
- //$tab1 .= "</table>\n";
- $tab2 .= "</table>\n";
- echo $tab1;
+ error_log("exif test page - checking files: ".count($possible)." done.",0);
echo $tab2;
+ echo "</table>\n";
} else {
echo "<h1 style='color:red'>function exif_read_data is not supported</h1>\n";
}
diff --git a/ext/exif/tests/001.phpt b/ext/exif/tests/001.phpt
index 35694264de..2fd3697936 100644
--- a/ext/exif/tests/001.phpt
+++ b/ext/exif/tests/001.phpt
@@ -23,4 +23,4 @@ foreach($image as $idx=>$section) {
echo $accept;
?>
--EXPECT--
-ArrayFitest2.jpgFi1015448798Fi1240Fi2SeCOMPUTED, ANY_TAG, IFD0, THUMBNAIL, COMMENTArrayCoPhoto (c) M.BoergerCoEdited by M.Boergehtwidth="1" height="1"He1Wi1Is1UsExif test image.UsASCIIArrayCoPhoto (c) M.BoergerUsASCIIArrayJP134JP523Array0Comment #1.1Comment #2.2Comment #3end \ No newline at end of file
+ArrayFitest2.jpgFi1015448798Fi1240Fi2SeANY_TAG, IFD0, THUMBNAIL, COMMENTArrayhtwidth="1" height="1"He1Wi1Is1UsExif test image.UsASCIICoPhoto (c) M.Boerger, Edited by M.Boerger.CoPhoto (c) M.BoergerCoPhoto (c) M.BoergerArrayCoPhoto (c) M.BoergerUsASCIIArrayJP134JP523Array0Comment #1.1Comment #2.2Comment #3end \ No newline at end of file