iptcembed() - gd函数(图像处理)
iptcembed()
(PHP 4, PHP 5, PHP 7)
将二进制 IPTC 数据嵌入到一幅 JPEG 图像中
说明
iptcembed (string $iptcdata,string $jpeg_file_name[,int $spool] ) : mixedEmbeds binary IPTC data into a JPEG image.
参数
$iptcdataThe data to be written.
$jpeg_file_namePath to the JPEG image.
$spoolSpool flag. If the spool flag is over 2 then the JPEG will be returned as a string.
返回值
If success and spool flag is lower than 2 then the JPEG will not be returned as a string, FALSE
on errors.
范例
Embedding IPTC data into a JPEG
注释
Note:此函数不需要 GD 图象库。
The following code embeds both IPTC APP segment 13 and EXIF APP segment 1 data from a source file and embeds it into a destination file. This overcomes the limitation where the iptcembed statement does not seem to embed EXIF data, only IPTC data. function transferIptcExif2File($srcfile, $destfile) { // Function transfers EXIF (APP1) and IPTC (APP13) from $srcfile and adds it to $destfile // JPEG file has format 0xFFD8 + [APP0] + [APP1] + ... [APP15] + where [APPi] are optional // Segment APPi (where i=0x0 to 0xF) has format 0xFFEi + 0xMM + 0xLL + (where 0xMM is // most significant 8 bits of (strlen() + 2) and 0xLL is the least significant 8 bits // of (strlen() + 2) if (file_exists($srcfile) && file_exists($destfile)) { $srcsize = @getimagesize($srcfile, $imageinfo); // Prepare EXIF data bytes from source file $exifdata = (is_array($imageinfo) && key_exists("APP1", $imageinfo)) ? $imageinfo['APP1'] : null; if ($exifdata) { $exiflength = strlen($exifdata) + 2; if ($exiflength > 0xFFFF) return false; // Construct EXIF segment $exifdata = chr(0xFF) . chr(0xE1) . chr(($exiflength >> 8) & 0xFF) . chr($exiflength & 0xFF) . $exifdata; } // Prepare IPTC data bytes from source file $iptcdata = (is_array($imageinfo) && key_exists("APP13", $imageinfo)) ? $imageinfo['APP13'] : null; if ($iptcdata) { $iptclength = strlen($iptcdata) + 2; if ($iptclength > 0xFFFF) return false; // Construct IPTC segment $iptcdata = chr(0xFF) . chr(0xED) . chr(($iptclength >> 8) & 0xFF) . chr($iptclength & 0xFF) . $iptcdata; } $destfilecontent = @file_get_contents($destfile); if (!$destfilecontent) return false; if (strlen($destfilecontent) > 0) { $destfilecontent = substr($destfilecontent, 2); $portiontoadd = chr(0xFF) . chr(0xD8); // Variable accumulates new & original IPTC application segments $exifadded = !$exifdata; $iptcadded = !$iptcdata; while ((substr($destfilecontent, 0, 2) & 0xFFF0) === 0xFFE0) { $segmentlen = (substr($destfilecontent, 2, 2) & 0xFFFF); $iptcsegmentnumber = (substr($destfilecontent, 1, 1) & 0x0F); // Last 4 bits of second byte is IPTC segment # if ($segmentlen In the future, I'll work on changing XMP datas and IPTC in the same way and will publish it ther or as a in PEAR. May the force be with us :-)
Yep it's me again :-) After some time I spent searching around for other possibilities to write IPTC fields to JPEG files I found this one: http://www.zonageek.com/software/php/jpeg/index.php This one seems to work pretty fine, remember that you have to install PEAR to get this running (Debian package php4-pear).
Example to read IPTC text from an image, changing the text an write to a new file using the functions iptcparse and iptcembed. Also a list of the most common IPTC fields. --- The most common IPTC Fileds 005 - Object Name 007 - Edit Status 010 - Priority 015 - Category 020 - Supplemental Category 022 - Fixture Identifier 025 - Keywords 030 - Release Date 035 - Release Time 040 - Special Instructions 045 - Reference Service 047 - Reference Date 050 - Reference Number 055 - Created Date 060 - Created Time 065 - Originating Program 070 - Program Version 075 - Object Cycle 080 - Byline 085 - Byline Title 090 - City 095 - Province State 100 - Country Code 101 - Country 103 - Original Transmission Reference 105 - Headline 110 - Credit 115 - Source 116 - Copyright String 120 - Caption 121 - Local Caption
For everybody having issues with unicode (UTF-8) text in IPTC fields, set the "Coded Character Set"-field in the envelop (1:90, see http://www.iptc.org/std/IIM/4.1/specification/IIMV4.1.pdf). This can be accomplished by starting the $data-block with the following lines: After that you can continue like in the example:
To remove all EXIF, XMP etc. tags from a jpeg file you need no resampling (which, by the way, may give you memory problems). It's just enough to recreate the image, presumably with 100% quality in order not to loose anything. The code is as simple as that:
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)