UTF-8字符无法从PHP中的JPEG IPTC数据正确显示 [英] UTF-8 characters not displaying properly from JPEG IPTC data in PHP

查看:86
本文介绍了UTF-8字符无法从PHP中的JPEG IPTC数据正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从图像读取IPTC数据时,通过PHP读取UTF-8重音字符时无法正确显示.

When reading the IPTC data from an image, UTF-8 accented characters are not displaying properly when reading them via PHP.

例如:é,ø和ü

将标题内容类型设置为UTF8,而不是字符,我得到了黑色菱形的问号. 如果未设置content-type,那么我得到一个破折号:-

With a header content-type set as UTF8, instead of the character, I get the question mark in a black diamond. � If no content-type is set, then I get a dash character: —

以下是用于读取IPTC块的代码:

The following is the code being used to read the IPTC block:

$file = '/path/to/image.jpg';
getimagesize($file, $info);
$iptc = iptcparse($info['APP13']);

我也尝试过将完全相同的图像上传到同一台服务器上的WordPress安装中,它会正确去除重音字符并将其替换为基本的拉丁语等效字符.我不介意这是否是最终结果,我只是想正确阅读这些字符.

I have also tried uploading the exact same image to a WordPress installation on the same server, and it properly strips the accented character and replaces it with it's basic latin equivalent. I don't mind if this is the end result, I would just like to read the characters properly.

关于如何从图像中获取完整和正确的数据的任何想法?

Any ideas on how to get the complete and correct data from the image?

推荐答案

回答得有点晚,但是由于我在显示特殊字符和č š ž(出现在斯洛文尼亚字母中)时遇到了同样的问题,所以我也可以作答以供将来参考.

Answering a bit late, but since I had the same problem displaying special characters as č š ž (which appear in Slovenian alphabet) I may aswell answer for future reference.

解决此问题的方法实际上与php无关,但与IPTC数据编码有关.默认情况下,大多数可以写入IPTC数据的软件都会将其存储为纯ASCII码.最初,我使用过Adobe Bridge-在开始标记图像时实际上会显示所有特殊字符-但是一旦您想在PHP中解析该数据,实际上就不会看到特殊字符. (我将不得不再次检查这一部分,但主要问题是发生了两种不同的编码-一种在图像上编码IPTC数据,另一种在可以处理IPTC数据的程序中显示该数据-或类似的东西)

Solution to this problem actually is not related to php, but to the IPTC data encoding. By default most software that can write IPTC data will store it in plain ASCII. At first I've used Adobe Bridge - which actually displays all special characters as it should when you start tagging your images - but once you want to parse that data in PHP you will actually not see special characters. (I would have to check again this part, but the main catch is that two different encodings happen - one that encodes IPTC data on the image and one that displays that data in a program that can handle IPTC data - or something along this lines).

为解决该问题,我使用了名为 ExifTool 的程序一个很棒的软件,它将使您可以管理图像上的几乎所有数据.

To solve the problem I used a program called ExifTool which is an amazing piece of software and will let you manage almost any data on your image.

然后用它将所有IPTC编码转换为UTF-8-从那时起,我只需要重新标记具有损坏字符的图像(Adobe Bridge可以正确显示,但显然不能以正确的编码保存).

Than I used it to convert all IPTC encodings to UTF-8 - and from then on I just had to retag images that had corrupt characters (which Adobe Bridge correctly displays but obviously does not save in correct encoding).

要对文件夹中的所有图像执行此操作的命令是:

The command to accomplish this on all images in a folder is:

exiftool -tagsfromfile @ -iptc:all -codedcharacterset=utf8

如果您不熟悉使用cmd进行操作,则可能还需要下载 ExifTool GUI .

You may also want to download ExifTool GUI if you are not familiar working from cmd.

我还没有找到更好的程序来更快地完成此任务.

I haven't found any better program that could accomplish this same task faster.

这篇关于UTF-8字符无法从PHP中的JPEG IPTC数据正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆