首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使IPTC数据可搜索

使IPTC数据可搜索
EN

Stack Overflow用户
提问于 2009-09-13 07:50:18
回答 2查看 2.2K关注 0票数 0

我有一个关于IPTC元数据的问题。有没有可能通过IPTC元数据(关键字)搜索不在数据库中的图像并显示它们,我该怎么做?我只需要一个基本的想法。

我知道PHP有iptcparse()函数。

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

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

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

感谢您在这个问题上的帮助。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-09-13 09:27:27

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

代码语言:javascript
复制
<?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;
}
票数 3
EN

Stack Overflow用户

发布于 2009-09-13 09:05:45

如果您没有从您的图像中提取这些IPTC数据,则每次有人搜索时,您将不得不:

在每个图像上提取

  • 循环对于每个图像,

  • 查看当前图像的IPTC数据是否与

匹配

如果你有两个以上的图像,这将是非常糟糕的表现,我会说。

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

在上传/存储图像时,在database

  • extract中添加几个字段相关的fields

  • search数据

  • 将这些数据存储在DB fields

  • search中的那些DB字段中

  • 或使用像Lucene或Sphinx这样的搜索引擎--但这是另一种方法

这意味着你现在需要做更多的工作:你有更多的代码要写……

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1417138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档