From 01378e19072b89c33af85a8a12a37f6c898e0941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 12 Jul 2013 15:08:13 +0200 Subject: incorporate development branch of ssh://irodsguest@code.renci.org/gitroot/irodsphp --- .../irodsphp/prods/utilities/exif2meta.php | 145 +++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 apps/files_external/3rdparty/irodsphp/prods/utilities/exif2meta.php (limited to 'apps/files_external/3rdparty/irodsphp/prods/utilities/exif2meta.php') diff --git a/apps/files_external/3rdparty/irodsphp/prods/utilities/exif2meta.php b/apps/files_external/3rdparty/irodsphp/prods/utilities/exif2meta.php new file mode 100644 index 00000000000..9ee9495f102 --- /dev/null +++ b/apps/files_external/3rdparty/irodsphp/prods/utilities/exif2meta.php @@ -0,0 +1,145 @@ +getMeta(); + $metaalreadyset = false; + foreach ($metas as $meta) { + if ($meta->name == 'EXIF.ExifVersion') { + $metaalreadyset = true; + break; + } + } + + if ($metaalreadyset === true) { + $time = '[' . date('c') . ']'; + echo "$time 0: metadata already set for '$target_file'\n"; + exit(0); + } + + // download file from irods to tmp + $localfile = '/tmp/' . basename($target_file); + if (file_exists($localfile)) + unlink($localfile); + $irodsfile->open("r"); + $str = ''; + while ((($buffer = $irodsfile->read(1024 * 1024)) != NULL) && + (connection_status() == 0)) { + $str = $str . $buffer; + } + $irodsfile->close(); + file_put_contents($localfile, $str); + + extactExif($localfile, $irodsfile); + + if (file_exists($localfile)) + unlink($localfile); + + $time = '[' . date('c') . ']'; + echo "$time 0: '$target_file' processed!\n"; + exit(0); + +} catch (Exception $e) { + + if (file_exists($localfile)) + unlink($localfile); + + $time = '[' . date('c') . ']'; + echo "$time " . $e->getCode() . ": " . "$e"; + exit(-1); +} + + +function extactExif($localfile, $remoteRODSfile) +{ + $exif = exif_read_data($localfile, 'EXIF'); + if ($exif === false) return; + + foreach ($exif as $name => $val) { + + // replace ascii char that can't be displayed, which causes problem in irods + if ((!is_array($val)) && (is_string($val)) && + ((ord($val[0]) < 32) || (ord($val[0]) > 126)) && + ($name != 'UserComment') + ) { + $val = '__undefined__'; + } + + if ($name == 'THUMBNAIL') { + foreach ($val as $tname => $tval) + $remoteRODSfile->addMeta(new RODSMeta( + 'EXIF.THUMBNAIL.' . $tname, $tval, '')); + } else + if ($name == 'COMPUTED') { + foreach ($val as $cname => $cval) { + if ($cname == 'html') { + //skip html tag, because there is a irods server bug that corrupting string with + //double quotes: 'COMPUTED.html: width="3264" height="2448"' + } else + $remoteRODSfile->addMeta(new RODSMeta( + 'EXIF.COMPUTED.' . $cname, $cval, '')); + } + } else + if ($name == 'MakerNote') { + //skip makernote + } else + if ($name == 'ComponentsConfiguration') { + //skip ComponentsConfiguration, because there is a irods server bug that corrupting string with + + } else + if ($name == 'UserComment') { + if (($start = strpos($val, 'GCM_TAG')) !== false) { + $str = substr($val, $start + strlen('GCM_TAG')); + $gcm_tokens = explode(chr(0), $str); + $gcm_counter = 0; + foreach ($gcm_tokens as $gcm_tag) { + if ((strlen($gcm_tag) > 0) && (preg_match('/^[' . chr(32) . '-' . chr(126) . ']+$/', $gcm_tag))) { + $remoteRODSfile->addMeta(new RODSMeta( + 'EXIF.UserComment' . $gcm_counter++, $gcm_tag, '')); + } + } + } else { + if (strlen($val) < 1) + $str = ' '; + //replace no displable char + $str = preg_replace('/[^' . chr(32) . '-' . chr(126) . ']+/', ' ', $val); + $remoteRODSfile->addMeta(new RODSMeta( + 'EXIF.UserComment', $str, '')); + } + } else + if (is_array($val)) { + foreach ($val as $cname => $cval) { + $remoteRODSfile->addMeta(new RODSMeta( + "EXIF.$name." . $cname, $cval, '')); + } + } else + $remoteRODSfile->addMeta(new RODSMeta( + 'EXIF.' . $name, $val, '')); + } +} + +?> -- cgit v1.2.3