svg - SVG过滤器:不同的颜色取决于浏览器
问题描述
我有一张黑白图像,我正在尝试使用 SVG 过滤器重新着色。Safari 中的颜色看起来比 Chrome 中的颜色要深得多,有什么方法可以让 Safari 看起来与 Chrome 更一致?
CSS代码如下
.container-teamMembers a.six img {
-webkit-filter: url(#duotone_bright_green);
-moz-filter: url(#duotone_bright_green);
-o-filter: url(#duotone_bright_green);
-ms-filter: url(#duotone_bright_green);
filter: url(#duotone_bright_green);
}
SVG过滤器是
<svg xmlns="http://www.w3.org/2000/svg" class="svg-filters">
<filter id="duotone_bright_green">
<feColorMatrix type="matrix" result="grayscale" values="1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
0 0 0 1 0"></feColorMatrix>
<feComponentTransfer color-interpolation-filters="sRGB" result="duotone_blue_black">
<feFuncR type="table" tableValues="0.03137254902 0.74509803921"></feFuncR>
<feFuncG type="table" tableValues="0.007843137255 0.81568627451"></feFuncG>
<feFuncB type="table" tableValues="0.02352941176 0.0431372549"></feFuncB>
<feFuncA type="table" tableValues="0 1"></feFuncA>
</feComponentTransfer>
</filter>
</svg>
谁能告诉我如何让 Safari 看起来更轻/与 Chrome 更一致?
解决方案
这看起来很愚蠢 - 但是将其color-interpolation-filters="sRGB"
移入过滤器元素而不是 feComponentTransfer - Safari 在将其放入原语时似乎不会检查它。
这是适合我的过滤器。我在较旧的 Macbook Pro(2016 年)上的 MacOS Mojave 上运行 Chrome 73 和 Safari 12.1。
<svg xmlns="http://www.w3.org/2000/svg" class="svg-filters">
<filter id="duotone_bright_green" color-interpolation-filters="sRGB">
<feColorMatrix type="matrix" result="grayscale" values="1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
0 0 0 1 0"></feColorMatrix>
<feComponentTransfer result="duotone_blue_black">
<feFuncR type="table" tableValues="0.03137254902 0.74509803921"></feFuncR>
<feFuncG type="table" tableValues="0.007843137255 0.81568627451"></feFuncG>
<feFuncB type="table" tableValues="0.02352941176 0.0431372549"></feFuncB>
<feFuncA type="table" tableValues="0 1"></feFuncA>
</feComponentTransfer>
</filter>
</svg>
这是屏幕截图——左边是 Chrome,右边是 Safari。
推荐阅读
- swagger - OpenAPI 规范中数组和对象查询参数的 URL 示例?
- python - 将子进程(Qprocess)脚本中的绘图嵌入到主父进程 - 主线程中的 Qgraphicsview
- android - 为什么超出单行 TextView 边界的单词不会被渲染和剪切?
- sql - 地址部分提取所需的 SQL 查询帮助
- sql - 表中每个唯一属性的新列的 SQL 查询
- html - 如何在一行中写两个文本
- 标签之间的间距相等 CSS
- windows - 使用 electron-builder 将电子应用程序打包到单个 .exe 安装程序中
- javascript - React Native Firestore 删除数组中的对象
- python - 如何解决“意外的关键字参数”错误
- android - 运行示例 Android Studio 应用程序时出现问题