被 gmail 代理阻止的 SVG 图像 [英] SVG images blocked by gmail proxy

查看:43
本文介绍了被 gmail 代理阻止的 SVG 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎新的 gmail 图像代理不适用于 SVG(如果您在新选项卡中打开代理 url,则会出现 404 错误.)

It seems like the new gmail proxy for images doesn't work with SVG (gives a 404 error if you open the proxy url in a new tab.)

我找不到任何有关支持/阻止的文件类型的文档.gmail 中的 SVG 是否适用于其他人?

I haven't been able to find any documentation about supported/blocked file-types. Is SVG in gmail working for anyone else?

我能想到的唯一解决方法是使用 PhantomJS 在服务器上生成 svg 的 png - 还有其他选项吗?

The only workaround I can think of is to generate a png of the svg on the server using PhantomJS - any other options?

背景:

这适用于发送每日摘要电子邮件的 web 应用程序,显示过去 24 小时的图表(因此 svg 每天都不同,将其放在电子邮件中可以为用户节省点击进入应用程序的麻烦.)

This is for a webapp that sends daily summary emails, showing a graph covering the last 24 hours (so the svg is different each day, having it in the email saves the user the hassle of clicking through to the app.)

我知道 SVG 图像在某些电子邮件客户端中无法使用,但 95% 可以使用,其余的仍然可以点击进入 web 应用程序.

I know that the SVG images won't work in some email-clients, but it'll work for 95%, the rest can still click through to the webapp.

在本月初代理更改之前,它在 gmail 中运行良好(本月底才刚刚推出到 Google Apps 帐户.)

It was working fine in gmail up until the proxy change earlier this month (which has only just rolled out to Google Apps accounts at the end of the month.)

推荐答案

我收到了 Google 支持的回复,他们确认目前没有计划在代理中支持 SVG 图像.他们说他们只占 100,000 张电子邮件图像中的 1 张.

I've heard back from Google support, and they've confirmed there are currently no plans to support SVG images in the proxy. They said they account for only 1 in 100,000 email images.

除了 PhantomJs,更简单的 svg 的一个选项是 php 插件 ImageMagick.

Apart from PhantomJs, an option for simpler svg is the php plugin ImageMagick.

这里有一些示例代码可以帮助您入门:

Here's some sample code to get you started:

header("Content-Type: image/png");
header("Content-Disposition: inline;");
if (empty($svg)) {
    readfile("invisibleImage.png", true);
} else {

    //TODO: You'll probably want to set headers to cache the returned image

    $filepath = "/path/to/where/images/are/cached/";

    if (!file_exists("$filepath$svgName.png")) {
        if (!is_dir($filepath)) {
            mkdir($filepath, 0700, 1);
        }
        file_put_contents("$filepath$svgName.svg", $svg);
        $cmd = "rsvg-convert $filepath$msk.svg > $filepath$svgName.png";
        exec($cmd);
        unlink("$filepath$svgName.svg");
    }
    readfile("$filepath$svgName.png");
}

您至少需要安装以下部分:

You'll want to install at least some of the following:

apt-get install librsvg2-bin libpng3 imagemagick libpng12-dev 

这篇关于被 gmail 代理阻止的 SVG 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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