css改变svg颜色_如何使用CSS混合模式和SVG动态更改产品图像的颜色

2023-11-18

css改变svg颜色

To better explain that title right off the bat, here’s what we’re about to learn, and it’s easier than you think. Give it a go, change the shirt from yellow to blue by using the color picker in the bottom right corner:

为了立即更好地解释该标题,这是我们将要学习的内容,它比您想象的要容易。 放手一搏,使用右下角的颜色选择器将衬衫从黄色更改为蓝色:

See the Pen Dynamic Colour Picking – Part 4 by Kyle Wetton (@kylewetton) on CodePen.

见笔动态彩色采摘- 4部分由凯尔Wetton( @kylewetton )上CodePen

You can see another example of this in the demo Color this sofa! where you can change the color of a sofa and its background gradient.

您可以在演示中看到另一个示例将此沙发着色! 您可以在其中更改沙发的颜色及其背景渐变。

Imagine this for a second: You’ve finally done it, over the summer, you and a buddy are about to launch your screen printing start up out of your shared house, it’s not much, but you have a working setup and a few local bands and non-profits have already shown interest. Your supplier for t-shirts, pants, hats and $2 sunglasses is exactly what you’ve been looking for, they supply 25 colors per item and you couldn’t be happier that your website has finally been signed off. Now all you need to do is upload some photos of your merchandise! Problem is, 25 colors per item? Thats 125 different options, how do you approach this?

想象一下:您终于完成了这个工作,在整个夏天,您和一个伙伴将要在您共享的房子外启动丝网印刷,这虽然不多,但是您有一个可以工作的设置以及一些本地设置。乐队和非营利组织已经表现出兴趣。 您的T恤,裤子,帽子和2美元太阳镜的供应商正是您所需要的,他们为每种商品提供25种颜色,对于您的网站最终被批准,您感到无比高兴。 现在,您需要做的就是上传一些商品照片! 问题是每件25种颜色? 多数民众赞成在125个不同的选择,您如何处理呢?

You’ve seen this often happen online, and the solution is almost always a picture of one color, and little dots that represent the rest of the options.

您已经看到这种情况经常在线发生,而解决方案几乎总是一张单色的图片,并用小点代表其余的选项。

And for good reason too, nobody wants to spend the time or money photographing someone wearing over 125 items, so like the masses before you, you get your friend to model one color of each and let your potential customer use their imagination to determine what the others look like based on a dotted color.

同样也有充分的理由,没有人愿意花费时间或金钱拍摄穿着125件以上商品的人,因此像您之前的群众一样,您可以让您的朋友为每种商品建模一种颜色,并让潜在客户利用他们的想象力来确定其他看起来像是基于虚线的颜色。

The reason for the preamble is to be clear about why the solution you’re about to learn is so valuable. With just a small to moderate amount of setup, you can take one photo of your product and let your web page dynamically change the color of a t-shirt, hat, sunglasses and pants to any color you throw at it, in fact, if you wanted to you can change all of these items independently on the same image, on the same web page, without it reloading.

前言的原因是要弄清楚为什么您要学习的解决方案如此有价值。 只需进行少量到中等的设置,您就可以拍摄产品的一张照片,并让您的网页将T恤,帽子,太阳镜和裤子的颜色动态地更改为您扔给它的任何颜色,实际上,如果您希望可以在同一图像,同一网页上独立地更改所有这些项目,而无需重新加载。

那么这是怎么回事? 这是什么魔术? (So what’s happening here? What magic is this?)

It’s an SVG element with an image behind it, and a vector shape (path element) drawn over the part(s) you want the color to change. You simply change the fill color of your path element, and use the CSS property mix-blend-mode: multiply to stain that color onto the image.

这是一个SVG元素,后面带有图像,并且在要更改颜色的零件上绘制了矢量形状( path元素)。 您只需更改path元素的填充颜色,然后使用CSS属性mix-blend-mode:乘法即可将该颜色着色到图像上。

让我们开始吧 (Let’s Get Started)

Download this photo if you’d like to follow along.</

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

css改变svg颜色_如何使用CSS混合模式和SVG动态更改产品图像的颜色 的相关文章

  • 我应该如何优化这个文件系统 I/O 绑定程序?

    我有一个 python 程序 它执行如下操作 从 csv 文件中读取一行 对其进行一些变换 将其分解为实际的行 因为它们将被写入数据库 将这些行写入单独的 csv 文件 除非文件已完全读取 否则返回步骤 1 运行 SQL Loader 并将
  • 这是在 python 中美白图像的正确方法吗?

    我在尝试着zero center and whiten CIFAR10数据集 但我得到的结果看起来像随机噪声 Cifar10数据集包含60 000尺寸的彩色图像32x32 训练集包含50 000和测试集包含10 000分别是图像 以下代码片
  • Jquery - 自动计算输入字段

    我正在尝试使下面的代码正常工作 我非常感谢您的帮助 基本上它是计算三个输入字段的总和 然后与其他两个字段相乘 最终结果应显示在输入字段 pcamount 中 这是 jsFiddle 中的示例 http jsfiddle net D98PW
  • 单击按钮时执行 python 脚本

    我有一个带有一个按钮的 HTML 页面 当我们单击该按钮时 我需要执行一个 python 脚本 并返回到包含结果的同一 HTML 页面 所以我需要对返回值进行一些验证并执行一些操作 这是我的代码 HTML
  • 为 Mercurial 执行 hgweb.cgi 时,指定的 CGI 应用程序行为不当...

    我有 IIS 6 我将 Mercurial 安装在 c program files mercurial 中 我在 c program files python 中安装了 Python 2 6 I added extension handli
  • 如何使用生成器遍历文件系统?

    我正在尝试创建一个实用程序类来遍历目录中的所有文件 包括子目录和子子目录中的文件 我尝试使用发电机 因为发电机很酷 然而 我遇到了困难 def grab files directory for name in os listdir dire
  • Pymacs 助手在 30 秒后未启动

    我见过其他关于此的问题 但没有一个得到真正的回答 而且没有一个是我的问题 我有一个新系统 emacs 23 1 Centos 6 2 我认为 我下载了最新的 pymacs 并安装了它 但是 我得到 error Pymacs helper d
  • 有效地减去不同形状的 numpy 数组

    使用 numpy 出色的广播规则 您可以减去形状 3 数组v来自形状 5 3 数组X with X v 结果是一个形状 5 3 数组 其中每一行i是有区别的X i v 有没有办法减去形状 n 3 数组w from X使得每一行w从整个数组中
  • UserDict 类的优点?

    使用有什么好处UserDict class 我的意思是 我真正得到的不是 class MyClass object def init self self a 0 self b 0 m MyClass m a 5 m b 7 我将写下以下内容
  • 使用请求和多处理时的奇怪问题

    请检查这个Python代码 usr bin env python import requests import multiprocessing from time import sleep time from requests import
  • 如何在 Ubuntu 上通过 pip 安装 python3 版本的软件包?

    我两者都有python2 7 and python3 2安装在Ubuntu 12 04 符号链接python链接到python2 7 当我输入 sudo pip install package name 它将默认安装python2的版本pa
  • Requests-html 导致 OSError: [Errno 8] 调用 html.render() 时执行格式错误

    我正在使用 requests html 并尝试渲染功能 但收效甚微 当我使用 python3 8 运行这个脚本时 usr bin python3 from requests html import HTML file scrape temp
  • 您忽略了哪些 PEP 8 准则,哪些是您坚持的? [关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 多年来 我编写的 Python 越多 我就越发现自己同意大多数准则 尽管我出于自己的原因始终有意地违反了一些准则 我很想知道 PEP 8 也可能
  • 如何在 Python 中小写字符串?

    有没有办法将字符串转换为小写 Kilometers kilometers See How to change a string into uppercase https stackoverflow com questions 9257094
  • 如何使用 python / pywinusb 将 hid 数据发送到设备?

    我正在尝试使用 pywinusb 将输出报告发送到 pic18f4550 该设备可以接收数据 我已经使用 C 应用程序对其进行了测试 效果很好 另外 我可以使用 pywinusb 从设备读取数据 但我在尝试发送数据时遇到问题 这是我正在运行
  • Pytest - 如何将参数传递给 setup_class?

    我有一些代码 如下所示 我得到了too few args当我运行它时出错 我没有打电话setup class明确地 所以不确定如何向它传递任何参数 我尝试用以下方法装饰该方法 classmethod 但仍然看到相同的错误 我看到的错误是这样
  • 使用 Angular JS 使图像出现在弹出窗口上

    这是我在 StackOverflow 上的第一篇文章 我正在自学 Angular 所以我是一个初学者 目前很困惑 我正在使用 Angular 创建一个网页 其中一个页面涉及一个按钮和一个弹出窗口 我想将图像放入弹出窗口中 但在实现此操作时遇
  • 当我将 HTML 标签设置为 100% 高度时,我的内容消失了

    我有一个垂直布局 我想保持页面居中 一列保持固定在页面上 而另一列应根据内容滚动 并且有一些绝对的装饰性浮动 div 我希望滚动列垂直显示 100 即使内容不需要高度 但我似乎无法让它工作 我已将 html 标签和 body 标签以及所有必
  • 如何使用电子表格中的第一行作为 Dataframe 列名称而不是 0 1 2...等?

    我希望我的数据框将第一行名称显示为数据框列名称 而不是从 0 等编号 我该如何执行此操作 我尝试使用 pandas 和 openpyxl 模块将我的 Excel 电子表格转换为数据框 import pandas as pd from ope
  • 从tensorflow 2.0 beta中的tf.data.Dataset检索下一个元素

    在tensorflow 2 0 beta之前 要从tf data Dataset中检索第一个元素 我们可以使用迭代器 如下所示 usr bin python import tensorflow as tf train dataset tf

随机推荐