可以将图像混合成颜色吗? (左、右、下)
是否可以将图像的左侧、右侧和底部混合成一种颜色?
可以说,我希望将图像混合成颜色“#F0F0F0”。我希望图像显示为背景的实际部分,所以我认为如果将其混合在一起看起来会很酷。
Is it possible to blend the left, right and bottom sides of an image into a color?
Lets say, I want the image to be blended into the color "#F0F0F0". I want the image to appear as an actual part of the background, so I thought it would look cool if it was blended in.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果这仅适用于网页,则可以使用基本的 HTML+CSS。就像你说的,你可以使用 PNG 作为背景上的停留(通过仔细定位的
)。
否则,请查看 PHP 的 ImageMagick 库,因为它们会让您以编程方式创建一个像您所描述的混合图像。 (
Imagick::colorizeImage
)If this is just for a webpage this is possible using basic HTML+CSS. Just like you said, you could use a PNG as a layover (via a carefully positioned
<div>
) on your background.Otherwise, look into the ImageMagick Libraries for PHP, as they'll let you programmatically create a blended image like you describe. (
Imagick::colorizeImage
)您可以使用图像操作库来完成此操作,例如 ImageMagick 或 GD。我发现此页面,作者在其中使用使用 GD 执行混合的梯度。
您还可以尝试使用
Imagick::colorizeimage
更新
根据您的屏幕截图,我不明白为什么您不能直接使用 HTML+CSS 来完成您想做的事情。您可以
使用透明PNG,也可以使用-moz-opacity
、opacity
或filter:alpha 在你的CSS中(跨浏览器透明度通过CSS)
。
You can do this by using an image-manipulation library like ImageMagick or GD. I found this page where the author uses a gradient to perform blending using GD.
You can also try using
Imagick::colorizeimage
UPDATE
Based on your screenshot, I don't see why you couldn't do what you wanted to with just straight HTML+CSS. You can
eitheruse a transparent PNGor you can use.-moz-opacity
,opacity
orfilter:alpha
in your CSS (Cross-browser Transparency via CSS)您必须操纵图像的像素数据才能实现此目的,但一旦您涵盖了这一点,它就不再是问题了。获取像素的颜色值并将其与您的混合颜色混合。有一些相当标准的数学可以很好地做到这一点,例如在进行多重纹理时像素着色器中经常使用的算法
value1 + (value2 - value1) * amount
。正如其他人所说,GD 等 php 图像库有助于图像的数据操作,因为您不必自己对其进行解码和编码
You would have to manipulate the pixeldata of the image to achieve this but once you have that covered its not really a problem. Take the color value of the pixel and blend it with your blendcolor. There are some pretty standard maths that can do it fairly well such as this algorithm
value1 + (value2 - value1) * amount
often used in pixelshaders when doing multi-texturing.As others have said image libraries for php such as GD helps out with the data manipulation of the image as you won't have to decode and encode it yourself
我不知道你到底需要什么,但是使用半透明 png 作为叠加层,你也可以做很多事情,而无需操作原始图像。
I don't know what you need exactly, but using a semi-transparent png as an overlay you can do a lot as well without the need to manipulate your original images.
我建议你使用 verot 的 upload php 类。它包含所有当前可用的处理图像的服务器端操作函数(旋转、色调、框架颜色、背景颜色等)。
请参阅此示例代码:
i suggest you use verot's upload php class. It contains all currently available serverside manipulation functions dealing with image (rotate, tint, frame color, background color, etc.).
See this sample code: