Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使IPTC数据可搜索_Php_Database_Search_Gallery_Iptc - Fatal编程技术网

Php 使IPTC数据可搜索

Php 使IPTC数据可搜索,php,database,search,gallery,iptc,Php,Database,Search,Gallery,Iptc,我有一个关于IPTC元数据的问题。是否可以通过IPTC元数据(关键字)搜索不在数据库中的图像并显示它们,以及我将如何执行此操作?我只需要一个基本的想法 我知道PHP有一个iptcparse()函数 我已经编写了一个函数,通过.jpg扩展名获取galleries文件夹和所有子目录中所有图像的图像名称、位置和扩展名 我需要弄清楚如何在不将元数据存储在数据库中的情况下提取元数据,如何在其中搜索,获取与搜索标签匹配的相关图像(它们的IPTC关键字应该匹配)以及如何显示它们。我知道在我有最终结果的时候(搜

我有一个关于IPTC元数据的问题。是否可以通过IPTC元数据(关键字)搜索不在数据库中的图像并显示它们,以及我将如何执行此操作?我只需要一个基本的想法

我知道PHP有一个iptcparse()函数

我已经编写了一个函数,通过.jpg扩展名获取galleries文件夹和所有子目录中所有图像的图像名称、位置和扩展名

我需要弄清楚如何在不将元数据存储在数据库中的情况下提取元数据,如何在其中搜索,获取与搜索标签匹配的相关图像(它们的IPTC关键字应该匹配)以及如何显示它们。我知道在我有最终结果的时候(搜索后),如果我在数组中有最终结果,我可以用src=“$filelocation”>回显imagetag

基本上,我不确定是否需要将所有图像存储到mysql数据库中,同时提取关键字并将其存储在数据库中,然后才能实际搜索和显示结果。另外,如果你能带我去任何一家已经能够做到这一点的画廊,那也会有所帮助


感谢您提供有关此问题的帮助。

如果您没有从图像中提取这些IPTC数据,每次有人搜索时,您必须:

  • 在每个图像上循环
  • 对于每个图像,提取IPTC数据
  • 查看当前图像的IPTC数据是否匹配
如果你有超过一对夫妇的形象,这将是非常糟糕的表现,我会说


因此,在我看来,最好是:

  • 在数据库中添加几个字段
  • 上传/存储图像时提取相关IPTC数据
  • 将IPTC数据存储在这些DB字段中
  • 在那些数据库字段中搜索
    • 或者使用诸如Lucene或Sphinx之类的搜索引擎——但这是另一个问题
这意味着你现在需要做更多的工作:你有更多的代码要写


。。。但这也意味着,当有多张图像和多个用户进行搜索时,您的网站将有更好的生存机会。

如果您没有从图像中提取这些IPTC数据,每次有人搜索时,您必须:

  • 在每个图像上循环
  • 对于每个图像,提取IPTC数据
  • 查看当前图像的IPTC数据是否匹配
如果你有超过一对夫妇的形象,这将是非常糟糕的表现,我会说


因此,在我看来,最好是:

  • 在数据库中添加几个字段
  • 上传/存储图像时提取相关IPTC数据
  • 将IPTC数据存储在这些DB字段中
  • 在那些数据库字段中搜索
    • 或者使用诸如Lucene或Sphinx之类的搜索引擎——但这是另一个问题
这意味着你现在需要做更多的工作:你有更多的代码要写


。。。但这也意味着,当有多张图片和许多用户进行搜索时,您的网站将有更好的生存机会。

不清楚是什么特别给您带来了问题,但这可能会给您一些想法:

<?php
# Images we're searching
$images = array('/path/to/image.jpg', 'another-image.jpg');

# IPTC keywords to values (from exiv2, see below)
$query = array('Byline' => 'Some Author');

# Perform the search
$result = select_jpgs_by_iptc_fields($images, $query);

# Display the results
foreach ($result as $path) {
    echo '<img src="', htmlspecialchars($path), '">';
}

function select_jpgs_by_iptc_fields($jpgs, $query) {
    $matches = array();
    foreach ($jpgs as $path) {
        $iptc = get_jpg_iptc_metadata($path);
        foreach ($query as $name => $values) {
            if (!is_array($values))
                $values = array($values);
            if (count(array_intersect($iptc[$name], $values)) != count($values))
                continue 2;
        }
        $matches[] = $path;
    }
    return $matches;
}

function get_jpg_iptc_metadata($path) {
    $size = getimagesize($path, $info);
    if(isset($info['APP13']))
    {
        return human_readable_iptc(iptcparse($info['APP13']));
    }
    else {
        return null;
    }
}

function human_readable_iptc($iptc) {
# From the exiv2 sources
static $iptc_codes_to_names =
array(    
// IPTC.Envelope-->
"1#000" => 'ModelVersion',
"1#005" => 'Destination',
"1#020" => 'FileFormat',
"1#022" => 'FileVersion',
"1#030" => 'ServiceId',
"1#040" => 'EnvelopeNumber',
"1#050" => 'ProductId',
"1#060" => 'EnvelopePriority',
"1#070" => 'DateSent',
"1#080" => 'TimeSent',
"1#090" => 'CharacterSet',
"1#100" => 'UNO',
"1#120" => 'ARMId',
"1#122" => 'ARMVersion',
// <-- IPTC.Envelope
// IPTC.Application2 -->
"2#000" => 'RecordVersion',
"2#003" => 'ObjectType',
"2#004" => 'ObjectAttribute',
"2#005" => 'ObjectName',
"2#007" => 'EditStatus',
"2#008" => 'EditorialUpdate',
"2#010" => 'Urgency',
"2#012" => 'Subject',
"2#015" => 'Category',
"2#020" => 'SuppCategory',
"2#022" => 'FixtureId',
"2#025" => 'Keywords',
"2#026" => 'LocationCode',
"2#027" => 'LocationName',
"2#030" => 'ReleaseDate',
"2#035" => 'ReleaseTime',
"2#037" => 'ExpirationDate',
"2#038" => 'ExpirationTime',
"2#040" => 'SpecialInstructions',
"2#042" => 'ActionAdvised',
"2#045" => 'ReferenceService',
"2#047" => 'ReferenceDate',
"2#050" => 'ReferenceNumber',
"2#055" => 'DateCreated',
"2#060" => 'TimeCreated',
"2#062" => 'DigitizationDate',
"2#063" => 'DigitizationTime',
"2#065" => 'Program',
"2#070" => 'ProgramVersion',
"2#075" => 'ObjectCycle',
"2#080" => 'Byline',
"2#085" => 'BylineTitle',
"2#090" => 'City',
"2#092" => 'SubLocation',
"2#095" => 'ProvinceState',
"2#100" => 'CountryCode',
"2#101" => 'CountryName',
"2#103" => 'TransmissionReference',
"2#105" => 'Headline',
"2#110" => 'Credit',
"2#115" => 'Source',
"2#116" => 'Copyright',
"2#118" => 'Contact',
"2#120" => 'Caption',
"2#122" => 'Writer',
"2#125" => 'RasterizedCaption',
"2#130" => 'ImageType',
"2#131" => 'ImageOrientation',
"2#135" => 'Language',
"2#150" => 'AudioType',
"2#151" => 'AudioRate',
"2#152" => 'AudioResolution',
"2#153" => 'AudioDuration',
"2#154" => 'AudioOutcue',
"2#200" => 'PreviewFormat',
"2#201" => 'PreviewVersion',
"2#202" => 'Preview',
// <--IPTC.Application2
      );
   $human_readable = array();
   foreach ($iptc as $code => $field_value) {
       $human_readable[$iptc_codes_to_names[$code]] = $field_value;
   }
   return $human_readable;
}

目前尚不清楚是什么特别给你带来了问题,但也许这会给你一些想法:

<?php
# Images we're searching
$images = array('/path/to/image.jpg', 'another-image.jpg');

# IPTC keywords to values (from exiv2, see below)
$query = array('Byline' => 'Some Author');

# Perform the search
$result = select_jpgs_by_iptc_fields($images, $query);

# Display the results
foreach ($result as $path) {
    echo '<img src="', htmlspecialchars($path), '">';
}

function select_jpgs_by_iptc_fields($jpgs, $query) {
    $matches = array();
    foreach ($jpgs as $path) {
        $iptc = get_jpg_iptc_metadata($path);
        foreach ($query as $name => $values) {
            if (!is_array($values))
                $values = array($values);
            if (count(array_intersect($iptc[$name], $values)) != count($values))
                continue 2;
        }
        $matches[] = $path;
    }
    return $matches;
}

function get_jpg_iptc_metadata($path) {
    $size = getimagesize($path, $info);
    if(isset($info['APP13']))
    {
        return human_readable_iptc(iptcparse($info['APP13']));
    }
    else {
        return null;
    }
}

function human_readable_iptc($iptc) {
# From the exiv2 sources
static $iptc_codes_to_names =
array(    
// IPTC.Envelope-->
"1#000" => 'ModelVersion',
"1#005" => 'Destination',
"1#020" => 'FileFormat',
"1#022" => 'FileVersion',
"1#030" => 'ServiceId',
"1#040" => 'EnvelopeNumber',
"1#050" => 'ProductId',
"1#060" => 'EnvelopePriority',
"1#070" => 'DateSent',
"1#080" => 'TimeSent',
"1#090" => 'CharacterSet',
"1#100" => 'UNO',
"1#120" => 'ARMId',
"1#122" => 'ARMVersion',
// <-- IPTC.Envelope
// IPTC.Application2 -->
"2#000" => 'RecordVersion',
"2#003" => 'ObjectType',
"2#004" => 'ObjectAttribute',
"2#005" => 'ObjectName',
"2#007" => 'EditStatus',
"2#008" => 'EditorialUpdate',
"2#010" => 'Urgency',
"2#012" => 'Subject',
"2#015" => 'Category',
"2#020" => 'SuppCategory',
"2#022" => 'FixtureId',
"2#025" => 'Keywords',
"2#026" => 'LocationCode',
"2#027" => 'LocationName',
"2#030" => 'ReleaseDate',
"2#035" => 'ReleaseTime',
"2#037" => 'ExpirationDate',
"2#038" => 'ExpirationTime',
"2#040" => 'SpecialInstructions',
"2#042" => 'ActionAdvised',
"2#045" => 'ReferenceService',
"2#047" => 'ReferenceDate',
"2#050" => 'ReferenceNumber',
"2#055" => 'DateCreated',
"2#060" => 'TimeCreated',
"2#062" => 'DigitizationDate',
"2#063" => 'DigitizationTime',
"2#065" => 'Program',
"2#070" => 'ProgramVersion',
"2#075" => 'ObjectCycle',
"2#080" => 'Byline',
"2#085" => 'BylineTitle',
"2#090" => 'City',
"2#092" => 'SubLocation',
"2#095" => 'ProvinceState',
"2#100" => 'CountryCode',
"2#101" => 'CountryName',
"2#103" => 'TransmissionReference',
"2#105" => 'Headline',
"2#110" => 'Credit',
"2#115" => 'Source',
"2#116" => 'Copyright',
"2#118" => 'Contact',
"2#120" => 'Caption',
"2#122" => 'Writer',
"2#125" => 'RasterizedCaption',
"2#130" => 'ImageType',
"2#131" => 'ImageOrientation',
"2#135" => 'Language',
"2#150" => 'AudioType',
"2#151" => 'AudioRate',
"2#152" => 'AudioResolution',
"2#153" => 'AudioDuration',
"2#154" => 'AudioOutcue',
"2#200" => 'PreviewFormat',
"2#201" => 'PreviewVersion',
"2#202" => 'Preview',
// <--IPTC.Application2
      );
   $human_readable = array();
   foreach ($iptc as $code => $field_value) {
       $human_readable[$iptc_codes_to_names[$code]] = $field_value;
   }
   return $human_readable;
}

您正在用相同编号的后续条目覆盖
$iptc_code_to_names
中的第一个条目。为什么不使用字符串作为该数组的索引呢?你是对的。我从exiv2 c源代码中复制了它,可能在将c代码转换为php代码时出错。我使用ints是因为。。。我可能认为代码应该是数字的。如果我使用数字串作为键,这几乎是一样的。(传入代码(如#0123)中的前导零不适用于字符串键,但这不是我使用ints的原因,否则我会对其进行注释)。您的代码仍然会导致
$iptc_codes_to_names[0]==“RecordVersion”
(值“ModelVersion”被覆盖)。恰好与IPTC.Application2字段具有相同编号的IPTC.信封字段丢失。我已经建议进行修改,但我还没有被接受。对我来说,索引是这样工作的:
$iptc_code_to_name['1#000']='ModelVersion'$iptc代码到名称['2#000']='RecordVersion'
。好吧,我想我明白了。$code上的substr()去掉了“#”前面的所有内容,实际上我丢失了一些信息。您正在用后面的相同数字覆盖
$iptc_codes_to_names
中的第一个条目。为什么不使用字符串作为该数组的索引呢?你是对的。我从exiv2 c源代码中复制了它,可能在将c代码转换为php代码时出错。我使用ints是因为。。。我可能认为代码应该是数字的。如果我使用数字串作为键,这几乎是一样的。(传入代码(如#0123)中的前导零不适用于字符串键,但这不是我使用ints的原因,否则我会对其进行注释)。您的代码仍然会导致
$iptc_codes_to_names[0]==“RecordVersion”
(值“ModelVersion”被覆盖)。恰好与IPTC.Application2字段具有相同编号的IPTC.信封字段丢失。我已经建议进行修改,但我还没有被接受。对我来说,索引是这样工作的:
$iptc_code_to_name['1#000']='ModelVersion'$iptc代码到名称['2#000']='RecordVersion'
。好吧,我想我明白了。$code上的substr()去掉了“#”之前的所有内容,实际上我丢失了一些信息。