我有一个问题是关于IPTC元数据。是否有可能搜索图片,不是在一个数据库通过其IPTC元数据(关键词),并显示他们和我怎么会去做这个?我只是需要一个基本思想。

我知道有iptcparse()function for PHP.

我已经写了一个功能抓住图象的姓名、位置,并扩展对于所有图像在画廊的文件夹和所有子目录。jpg扩展。

我需要找出如何提取的元数据没有存储在一个数据库以及如何通过搜索它,抓住相关的图片,配合搜索标签(其IPTC关键词匹配)和如何显示它们。我知道在这一点上,我们最终的结果(后搜索)我可以回一个imagetag与src="$filelocation">如果我最终结果在一个阵列。

基本上,我不确定如果我需要保存我所有的图像转换成一个数据库,并且提取的关键字并将其存储在数据库之前,我实际上可以搜索和显示的结果。还有,如果你能指引我任何馆已经能够做到这一点,这可能会有所帮助。

谢谢你任何帮助关于这个问题。

有帮助吗?

解决方案

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

<?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数据自己的图像,每次有人将搜索,只要:

  • 环路上的每一个图像
  • 每个图像中提取的数据IPTC
  • 看看如果IPTC数据,当前图像匹配

如果你有超过一对夫妇的形象,这将真正糟糕的表演我说的。


因此,在我看来,它会更好:

  • 添加一些领域在你的数据库
  • 提取相关IPTC数据在图像上传/储存
  • 存储IPTC数据,这些数据域
  • 搜索这些数据域
    • 或者使用某些搜索引擎像分类:设或狮身人面像的-但这是另一个问题。

这将意味着更多的工作对于你现在:你有更多的代码写的...

...但是,这也意味着您的网站将有更好的机会生存时,有几个图像和多的用户做的搜索。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top