不能一个base64-CN codeD映像添加到电子名片 [英] can't add a base64-encoded image to vCard

查看:195
本文介绍了不能一个base64-CN codeD映像添加到电子名片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地使用Perl的(通过Embperl)为员工创造一个动态生成的电子名片,填充所有字段除了照片。我不能得到工作不管。 (在code生成照片少名片正常工作。)

I've successfully used Perl (via Embperl) to create a dynamically-generated vCard for employees, populating all the fields except for the photo. I can't get that working no matter what. (The code to generate a photo-less vCard works fine.)

据有关资料,我可以在网上找到,图像的必须的使用base64-CN $ C $的电子名片本身的CD。电子名片规范(我使用3.0)支持URL链接的图像,但我的iPhone不会链接到他们的方式。所以这是一个base64或没有。

According to the information I can find online, the image must be base64-encoded in the vCard itself. The vCard spec (I'm using 3.0) supports URL-linked images, but my iPhone won't link to them that way. So it's base64 or nothing.

现在,我知道的Base64编码的作品,因为如果使用code到只显示一个图像...

Now, I know the base64-encoding works, because if use the code to just show an image...

[-
$photo = "/path/to/directory/".$employeeID.".jpg";
open($file, "<", $photo) || warn "Can't open $photo: $!\n";
#binmode $file;
$jpg = join('', <$file>);
$decoded = MIME::Base64::encode_base64($jpg);
$vcard_content  = $decoded;
-]
<img src="data:image/jpeg;base64,[+ $decoded +]">

...那么照片完美地显示在我的浏览器。 (有人建议我需要 binmode $文件; 在那里,但去除它似乎就在输出时没有什么区别。)

...then the photo shows up perfectly in my browser. (Someone suggested I needed binmode $file; in there, but removing it seems to make no difference in the output.)

但是,如果我将其包含在电子名片代替,照片根本不与接触其他数据显示:

But if I include it in the vCard instead, the photo simply doesn't show up with the rest of the contact data:

$vcard_content  = "BEGIN:VCARD\r";
$vcard_content .= "VERSION:3.0\r";
$vcard_content .= "N:".$v_last.";".$v_first.";".$v_middle.";;\r";
# etc.
$vcard_content .= "PHOTO;ENCODING=b;TYPE=JPEG:".$decoded."\r";
# etc.
$vcard_content .= "END:VCARD";

我是否误格式化vCard数据不知何故?

Am I mis-formatting the vCard data somehow?

推荐答案

导入名片到OS X通讯录,再出口,然后用文本编辑器查看导出电子名片后,我注意到,base64-的第一部分EN codeD映像在那里,但其余的不是。编码正确停止的地方一个空格( \\ r 显然)本色出演,连接codeD字符串。

After importing the vCard into OS X Contacts and exporting it again, then viewing the exported vCard with a text editor, I noticed that the first part of the base64-encoded image was there but the rest was not. The encoding stopped right where a whitespace (\r apparently) character appeared in the encoded string.

所以我删除从base64编码的所有空格字符构建电子名片前:

So I removed all the whitespace characters from the base64 encoding before building the vCard:

$decoded = MIME::Base64::encode_base64($jpg);
$decoded =~ s/\s//g;

和现在的照片导入正确。

And now the photo imports correctly.

这篇关于不能一个base64-CN codeD映像添加到电子名片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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