php 解析 标记,PHP 将二进制 IPTC 块解析为单个标记

用户评论:

www.peterdebruin.net (2011-07-22 13:12:44)

Nowadays IPTC captions may be encoded in UTF-8.

In that case, IPTC tag CodedCharacterSet would be set to "ESC % G".

This tag has tag marker "1#090".

To decode such a caption into simple ISO-8859-1, you could use the following code:

$IPTC_Caption="";$size=getimagesize($image_path,$info);

if (isset($info["APP13"])) {

if($iptc=iptcparse($info["APP13"] ) ) {$IPTC_Caption=str_replace("\000","",$iptc["2#120"][0] );

if(isset($iptc["1#090"]) &&$iptc["1#090"][0] =="\x1B%G")$IPTC_Caption=utf8_decode($IPTC_Caption);

}

}?>

Of course, this will only preserve ISO-8859-1 characters.

For proper Unicode support, you should convert UTF-8 byte sequences into HTML character entities, or encode the whole web page in UTF-8.

michael wells (2004-09-03 05:06:53)

To import IPTC keywords (which are stored in an array) into a scalar, try this sort of approach:

$keywordcount = count($iptc["2#025"]);

for ($i=0; $i

(you could strip the trailing space if you wanted).

If you are importing data from some Mac applications, they may put chr(213) into strings to access a closing quote character. This prints as a captial O with a tilde above it in a web browser or on Windows. You can fix this with:

function ConvertChars($in)

{

return str_replace(chr(213),"'",$in);

}

We use aspects of this code at www.thirdlight.com when parsing IPTC tags. XMP seems to be the better solution these days (being XML based is a great improvement!!).

evan at nospam dot ozhiker dot com (2004-08-09 09:57:51)

You might have noticed that several metadata fields in Photoshop are not available via IPTC.

I have written a library "PHP JPEG Metadata Toolkit" which fixes this problem as it allows reading, writing and interpreting of virtually any type of metadata, including these missing fields.

Try it out, and download it at:

http://www.ozhiker.com/electronics/pjmt/index.html

(2004-02-05 23:17:16)

View all availiable IPCT Data

function output_iptc_data( $image_path ) {

$size = getimagesize ( $image_path, $info);

if(is_array($info)) {

$iptc = iptcparse($info["APP13"]);

foreach (array_keys($iptc) as $s) {

$c = count ($iptc[$s]);

for ($i=0; $i

{

echo $s.' = '.$iptc[$s][$i].'
';

}

}

}

}

Scin (2002-10-14 15:52:25)

If you are not sure where a particular value you entered into the IPTC block in photoshop or any other software is being stored, simply run a foreach loop thru the block and find out:

(Insert a new paragraph in the beggening of the first echo)

$size = GetImageSize ("testimg.jpg", &$info);

$iptc = iptcparse($info["APP13"]);

foreach($iptc as $key => $value)

{

echo "IPTC Key: $key Contents: ";

foreach($value as $innerkey => $innervalue)

{

if( ($innerkey+1) != count($value) )

echo "$innervalue, ";

else

echo "$innervalue";

}

}

(2002-04-25 19:28:03)

Just to add to the above response, he missed a couple of IPTC tags:

Keywords:

$iptc["2#025"][n]; (there is a list of keywords)

Caption Writer:

$iptc["2#122"][0];

Just figured I'd note it, as the keywords can be quite important for database applications. I got these by extracting IPTC tags from a Photoshop 6.0 file, so hopefully they are standardized ;)

pkrohn at daemonize dot com (2001-07-15 16:35:48)

This took me longer than it ought to to figure out. Very handy for handling a stream of photos where the info you want is in the IPTC header. This example passes by reference, for which PHP4 will yell at you. If your need to write into the header, check out the Image::IPTCInfo Perl module.

$size = GetImageSize ("$image_name",&$info);

$iptc = iptcparse ($info["APP13"]);

if (isset($info["APP13"])) {

$iptc = iptcparse($info["APP13"]){

if (is_array($iptc)) {

$caption = $iptc["2#120"][0];

$graphic_name = $iptc["2#005"][0];

$urgency = $iptc["2#010"][0];

$category = $iptc["2#015"][0];

// note that sometimes supp_categories contans multiple entries

$supp_categories = $iptc["2#020"][0];

$spec_instr = $iptc["2#040"][0];

$creation_date = $iptc["2#055"][0];

$photog = $iptc["2#080"][0];

$credit_byline_title = $iptc["2#085"][0];

$city = $iptc["2#090"][0];

$state = $iptc["2#095"][0];

$country = $iptc["2#101"][0];

$otr = $iptc["2#103"][0];

$headline = $iptc["2#105"][0];

$source = $iptc["2#110"][0];

$photo_source = $iptc["2#115"][0];

$caption = $iptc["2#120"][0];}}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值