PHP/(不良)exif数据/警告,怎么办? [英] PHP/(bad) exif data/warnings, what to do?
问题描述
我正在编写一个小脚本,该脚本从图像中收集几个exif值...即创建日期,制造商和模型.
I'm writing a small script that gathers a couple exif values from images... namely the creation date, make and model.
我注意到(特别是通过默认iPhone邮件应用程序发送的图像)exif数据已被更改,这是一个已知问题(即使选择了原尺寸",邮件应用程序也会在发送图像之前压缩图像) ).我正在寻找的值似乎在那里,尽管我收到访问它们的PHP警告.实际获取值没有问题,但警告显然对我不起作用.
I'm noticing (particularly with image mailed through the default iPhone mail app) that the exif data has been altered, which is a known issue (the mail app compresses images before sending them, even when 'full size' is selected). The values I'm looking for appear to be there, although I get PHP warnings accessing them. No problems actually getting the values, but the warning obviously isn't working for me.
调用ini_set('display_errors',0)隐藏了警告,但对我来说似乎很草率.对于这种情况,我有什么办法可以忽略此脚本上的警告吗?
Calling ini_set('display_errors',0) hides the warnings, but seems sloppy to me. Is there any way I can ignore this warning, on this script, for this scenario that is a little better?
我最初的想法是将所有内容都包装在try/catch中,但是警告仍然显示在页面上.
My initial thought was wrapping everything in a try/catch, but the warning is still displayed prominently on the page.
我只是使用标准的exif_read_data()函数,我认为外部库可以满足我的需要.
I'm simply using the standard exif_read_data() function, I think an external library would be a little much for what little I need.
PHP:
if($_GET['i']) {
$input = strtolower($_GET['i'] . ".jpg");
if(file_exists($input)) {
$exif = exif_read_data($input);
foreach($exif as $key => $value) {
if(!in_array($key, Array("DateTime","Make","Model"))) {
unset($exif[$key]);
}
}
ksort($exif);
print_r($exif);
}
}
警告:
Warning: exif_read_data(trailmarker.jpg) [exif_read_data]: Illegal IFD size: x00C4 + 2 + x3239*12 = x25B70 > x2B74 in C:\xampp\htdocs\exif\dumpfolder\exif.php on line 5
Warning: exif_read_data(trailmarker.jpg) [exif_read_data]: Illegal IFD size: x00C4 + 2 + x3239*12 = x25B70 > x2B74 in C:\xampp\htdocs\exif\dumpfolder\exif.php on line 5
推荐答案
You can use the @ operator to hide the warning without using display_errors, i.e.
$exif = @exif_read_data(..);
这比设置 display_errors
更好,因为它仅使exif读取功能上的警告/错误静音,并且不会在代码中隐藏其他可能的错误.
That's better than setting display_errors
because it silences warnings/errors on the exif read function only, and does not hide other possible errors in your code.
这篇关于PHP/(不良)exif数据/警告,怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!