I am trying to add sharped cut effect on text. I have achieved this thing:
But I want to achieve this backplate/background sharped cut text effect:
My Code:
.wrapper {
background-color: #000;
}
.previewText {
text-shadow: var(--text-color) 0px 0px 10px, var(--text-color) 0px 0px 25px, #000 1px 1px 1px;
--text-color: #fff;
}
.previewText svg {
position: absolute;
left: 0;
top: 0;
z-index: 0;
}
<div class="wrapper">
<div class="preview-items--item__text previewText cut-sharp" style="font-family: Amarila; font-size: 50px; --text-color:#30cbfd;">
<div style="filter: url("#cutSharpru5i2bye4iml4tvt6s0");">
<p>work <span style="font-family: PoiretOne;">HARD</span></p>
<p><span style="font-family: PoiretOne;">dream</span> big</p>
</div>
<svg viewBox="0 0 100 100">
<filter id="cutSharpru5i2bye4iml4tvt6s0">
<feMorphology in="SourceGraphic" result="dilated" operator="dilate" radius="2.5"></feMorphology>
<feFlood flood-color="#fff" flood-opacity="0.12" result="neon"></feFlood>
<feComposite in="neon" in2="dilated" operator="in" result="cutSharpru5i2bye4iml4tvt6s0"></feComposite>
<feMerge>
<feMergeNode in="cutSharpru5i2bye4iml4tvt6s0"></feMergeNode>
<feMergeNode in="SourceGraphic"></feMergeNode>
</feMerge>
</filter>
</svg>
</div>
</div>
Can someone help me to achieve that thing as shown in the image #2? I am stuck. I tried a lot but i just got a little bit of a stroke with svg, the stroke should be in the full background of texts as shown in the image #2.
You need to use lighting primitives to get those edge lighting effects. Lighting primitives are buggy and usually trigger some kind of weird cross-browser bug then when you try to run them on Safari. Even Chrome runs into issues with them because they're just not very well debugged.
That caveat provided - this is the basic structure of how you'd accomplish something like this. It's a painstaking process of trial and error to figure out the exact right combination of lighting effect attributes to get exactly what you want - so this is something in the right neighborhood but I would not claim this is professional quality yet.
I would probably recommend Photoshop rather than SVG filters for this kind of effect.
body {
background-color: black;
}
.meow {
font-family: 'Meow Script', cursive;
font-size: 11pt;
font-weight: light;
fill: #faf;
stroke: none;
}
.comfort {
font-family: 'Comfortaa', sans-serif;
font-size: 11pt;
font-weight: light;
fill: #FAF;
stroke: none;
}
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Meow+Script&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Comfortaa:wght#300&display=swap" rel="stylesheet">
</head>
<body>
<svg width="800px" height="600px" viewBox="0 0 100 100">
<defs>
<filter id="shiny-filter" height="200%" color-interpolation-filters="sRGB">
<!-- Part 1 neon text -->
<feMorphology operator="dilate" radius="0.25" result="dilated-original"/>
<feGaussianBlur stdDeviation="0.75"/>
<feColorMatrix type="matrix" values="1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1.1 0"
result="glow"/>
<feComposite operator="over" in2='SourceGraphic' result="neon-text"/>
<!-- Part 2 drop shadow -->
<feGaussianBlur stdDeviation="0.5" in="dilated-original" result="blurred-dil-orig"/>
<feFlood flood-color="#111"/>
<feComposite operator="in" in2="blurred-dil-orig"/>
<feOffset dy="4" result="drop-shadow-y"/>
<feComposite operator="over" in="neon-text" in2="drop-shadow-y" result="neon-text-and-shadow"/>
<!-- Part 3 backplate -->
<feMorphology radius="2" operator="dilate" in="dilated-original" result="super-dilated-original"/>
<feFlood x="9.5" y="4" width="72" height="30" flood-color="#111"/>
<feComposite operator="over" in="super-dilated-original"/>
<feGaussianBlur stdDeviation="1" result="combined-backdrop"/>
<feFlood flood-color="#222"/>
<feComposite operator="in" in2="combined-backdrop" result="combined-backdrop-grey"/>
<!-- Part 4 lighting -->
<feSpecularLighting in="combined-backdrop-grey" result="topOut" specularExponent="15" lighting-color="#FcF" surfaceScale="2">
<fePointLight x="50" y="-150" z="10"/>
</feSpecularLighting>
<feSpecularLighting in="combined-backdrop-grey" result="leftOut" specularExponent="15" lighting-color="#FcF" surfaceScale="2" >
<fePointLight x="-150" y="50" z="10"/>
</feSpecularLighting>
<feSpecularLighting in="combined-backdrop-grey" result="rightOut" specularExponent="15" lighting-color="#FcF" surfaceScale="2" >
<fePointLight x="150" y="50" z="10"/>
</feSpecularLighting>
<feMerge>
<feMergeNode in="combined-backdrop-grey"/>
<feMergeNode in="neon-text-and-shadow"/>
<feMergeNode in="leftOut"/>
<feMergeNode in="topOut"/>
<feMergeNode in="rightOut"/>
</feMerge>
</filter>
</defs>
<g transform="translate(0 3)" filter="url(#shiny-filter)">
<text class="meow" x="10" y="11">work</text>
<text class="comfort" x="38" y="14">HARD</text>
<text class="comfort" x="9" y="33">DREAM</text>
<text class="meow" x="73" y="33">big</text>
</g>
</svg>
Situation/Problem
When making a SVG filter, I stumbled upon something strange. When converting the original CSS gradient to R, G or B color only (whichever channel has the highest value), I get dithering in the gradient.
Question
While this usually is a good thing for visual performance, it now messes up the calculations/masking in my SVG <filter>.
Is there a way to disable this dithering? Or to prevent it from occurring?
Example
* { margin: 0; padding: 0; box-sizing: border-box; font-family: sans-serif; }
.wheel {
display: block;
width: 100%;
height: 50px;
/* background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); */
/* background: linear-gradient(to right, #f88, #ff8, #8f8, #8ff, #88f, #f8f, #f88); */
/* background: linear-gradient(to right, #f44, #ff4, #4f4, #4ff, #44f, #f4f, #f44); */
background: linear-gradient(to right, #ffe0e0, #ffffe0, #e0ffe0, #e0ffff, #e0e0ff, #ffe0ff, #ffe0e0);
}
.very-light {
background: linear-gradient(to right, #fffafa, #fffffa, #fafffa, #faffff, #fafaff, #fffaff, #fffafa);
}
.filter {
filter: url(#max-channel);
/* Does not change gradient dithering behaviour */
/*transform: translateZ(0);*/
}
.expected {
background: linear-gradient(
to right,
#f00 0%,
#f00 calc((1/6) * 100%),
#0f0 calc((1/6) * 100%),
#0f0 calc((3/6) * 100%),
#00f calc((3/6) * 100%),
#00f calc((5/6) * 100%),
#f00 calc((5/6) * 100%),
#f00 100%
);
}
<div class="wheel">Original <code>linear-gradient()</code></div>
<div class="wheel filter"><code>linear-gradient()</code> with SVG filter applied</div>
<div class="wheel filter very-light">Even worse on very light gradient..!</div>
<div class="wheel expected">Expected result</div>
<svg
version="1.1" xmlns="http://www.w3.org/2000/svg"
width="0" height="0"
>
<filter id="max-channel" x="0" y="0" width="100%" height="100%" color-interpolation-filters="sRGB">
<feFlood flood-color="#ff0000" result="red" />
<feFlood flood-color="#00ff00" result="green" />
<feFlood flood-color="#0000ff" result="blue" />
<!-- Separate channels -->
<feComponentTransfer in="SourceGraphic" result="r-channel">
<feFuncR type="table" tableValues="0 1"></feFuncR>
<feFuncG type="table" tableValues="0 0"></feFuncG>
<feFuncB type="table" tableValues="0 0"></feFuncB>
</feComponentTransfer>
<feComponentTransfer in="SourceGraphic" result="g-channel">
<feFuncR type="table" tableValues="0 0"></feFuncR>
<feFuncG type="table" tableValues="0 1"></feFuncG>
<feFuncB type="table" tableValues="0 0"></feFuncB>
</feComponentTransfer>
<feComponentTransfer in="SourceGraphic" result="b-channel">
<feFuncR type="table" tableValues="0 0"></feFuncR>
<feFuncG type="table" tableValues="0 0"></feFuncG>
<feFuncB type="table" tableValues="0 1"></feFuncB>
</feComponentTransfer>
<!-- Red is max mask -->
<feBlend mode="lighten" in="SourceGraphic" in2="red" result="r-lighten" />
<feBlend mode="difference" in="SourceGraphic" in2="r-lighten" result="r-lighten-diff" />
<feColorMatrix type="matrix" in="r-lighten-diff" result="r-max-mask"
values="0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 -255 0 0 0 1"
/>
<!-- Green is max mask -->
<feBlend mode="lighten" in="SourceGraphic" in2="green" result="g-lighten" />
<feBlend mode="difference" in="SourceGraphic" in2="g-lighten" result="g-lighten-diff" />
<feColorMatrix type="matrix" in="g-lighten-diff" result="g-max-beforemask"
values="0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 -255 0 0 1"
/>
<feComposite operator="out" in="g-max-beforemask" in2="r-max-mask" result="g-max-mask" />
<!-- Blue is max mask -->
<feBlend mode="lighten" in="SourceGraphic" in2="blue" result="b-lighten" />
<feBlend mode="difference" in="SourceGraphic" in2="b-lighten" result="b-lighten-diff" />
<feColorMatrix type="matrix" in="b-lighten-diff" result="b-max-beforemask"
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 -255 0 1"
/>
<feComposite operator="out" in="b-max-beforemask" in2="r-max-mask" result="b-max-beforemask2" />
<feComposite operator="out" in="b-max-beforemask2" in2="g-max-mask" result="b-max-mask" />
<feMerge>
<!-- <feMergeNode in="SourceGraphic" /> -->
<!-- <feMergeNode in="r-channel" /> -->
<!-- <feMergeNode in="r-lighten-diff" /> -->
<feMergeNode in="b-max-mask" />
<feMergeNode in="g-max-mask" />
<feMergeNode in="r-max-mask" />
</feMerge>
</filter>
</svg>
Screenshot
Here you have two color wheel bars. The bottom one has the SVG filter applied to it. The filter should show full red on colors where red is the (shared) highest channel, then green, then blue. Ideally it would show 4 blocks that are, if added, have almost equal width. But as you can see, the dithering messes this up, and thus the blocks are dithered areas. For very light color gradients it's even worse.
Platform: Windows 10 - Browser: Chrome version 93.0.4577.82 (64-bit) (But happens in Edge as well.)
Notes:
I tried adding transform: translateZ(0) to the element to force it to hardware acceleration, but it makes no difference.
I found a thread on adding dithering to Chromium browsers, but not sure if this has happened.
Update
As suggested by Michael, I tried using a blur before applying the rest of the filter. By adding <feGaussianBlur stdDeviation="1" in="SourceGraphic" result="blurred-img" /> to the filter and using blurred-img instead of SourceGraphic. But as you can see from the screenshot below, it does not disable the dithering or deals with the 'troubled' pixels.
The trouble there is that they probably have a very small positive value because of calculations, but so small that dithering kicks in instead of assuming 0 opacity.
With blur of 1 px
FYI
So although it does not really have something to do with the question, I will explain the use case a bit.
In short, this filter will be used to effect a specific range of colors of the original image based on their hue value.
In order to do that, this filter above makes a mask that will ‘select’ a certain range of colors. The result can then be put through the actual effect and then pasted over the original image. For example all red tones in an image get hue rotated.
The easiest way to undo dithering is to add a small blur to the source graphic and use that result instead of the SourceGraphic as input.
Is it possible to transform a font with CSS to have rounded edges?
I'm talking about an effect similar to this smooth edges in Photoshop
So far I tried using a SVG filter, but it seems a bit complicated.
Is there a better way?
The code for the SVG filter used is this:
<svg viewbox="0 0 100% 100%">
<defs>
<filter id="smooth">
<feMorphology operator="dilate" radius="0" />
<feGaussianBlur stdDeviation="3" />
<feComponentTransfer>
<feFuncA type="table" tableValues="0 0 1 1"></feFuncA>
</feComponentTransfer>
<feComponentTransfer>
<feFuncA type="table" tableValues="0 0 1 1"></feFuncA>
</feComponentTransfer>
<feComponentTransfer out="rounded1">
<feFuncA type="table" tableValues="0 0 1 1"></feFuncA>
</feComponentTransfer>
<feComposite in2="rounded1" in="SourceGraphics" operator="in"/>
</filter>
</defs>
</svg>
and the explanations are here: https://dev.to/codingdudecom/css-smooth-font-edges-3pbb
One possible solution is using a goo filter like so. As an observation you need to know that for a different font and a different font-size you may need to change the values of the feColorMatrix and stdDeviation
div {
height: 200px;
padding:10px 60px;
font-size:200px;
font-family:Arial;
filter:url(#goo);
}
svg{position:absolute;}
<svg width="0" height="0">
<defs>
<filter id="goo">
<feGaussianBlur in="SourceGraphic" stdDeviation="7" />
<feColorMatrix mode="matrix" values="1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 35 -7" />
<feBlend in="SourceGraphic" />
</filter>
</defs>
</svg>
<div>
<span>A B</span>
</div>
Please read about The Goeey Effect
It's the first time I'm going to use SVG graphics and I'm a bit confused… I've researched extensively but I cannot seem to find an answer to what I'm trying to do.
I want to give an image the following appearance, given the source image is a color image.
The main reason behind this effect is to overcome bad quality images (both in terms of aesthetics and resolution) my clients might upload to their websites.
In Photoshop this is a Gradient Map and a transparent grid in Mode Multiply.
I've managed to apply a filter for the grayscale and "gradient map" but I cannot add the grid/pattern.
This is my code so far:
SVG file gradient-map.svg
<svg xmlns="http://www.w3.org/2000/svg">
<filter id="duotone_filter">
<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">
<feFuncR type="table" tableValues="0.0039525691 0.5764705882"></feFuncR>
<feFuncG type="table" tableValues="0.0123456790 0.8431372549"></feFuncG>
<feFuncB type="table" tableValues="0.0123456790 0.9803921569"></feFuncB>
<feFuncA type="table" tableValues="0 1"></feFuncA>
</feComponentTransfer>
</filter>
</svg>
HTML
<div class="image">
<img src="link/to/file" />
</div>
CSS
.image {
filter: url('../images/gradient-map.svg#duotone_filter');
}
And the SVG file for the pattern/fill
<svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="6px" height="6px" viewBox="0 0 6 6">
<circle cx="3" cy="3" r="2" />
</svg>
Is this the way things should be done? How should I proceed to achieve this effect?
If you could also link me to useful resources I would much appreciate. I haven't found any recent guides or articles.
Thanks.
You're on the right track. Here's a demo I put together (and on Codepen). And the output:
There's a helpful question to Overlay grid on responsive image, but I opted for simply overlaying and scaling a large transparent PNG. You'll likely end up with better results if you use a small, repeating grid section. Of course you'll have to choose what color, size, etc. to make the grid overlay.
As a side note, you cannot use the :after or :before pseudo-elements with img elements, so you need to wrap them in a container. You could also accomplish this with an additional element, like:
<div class="img-container">
<img src="..." />
<div class="grid-overlay"></div>
</div>
But I prefer pseudo-elements so I don't have to repeat <div class="grid-overlay"></div> every time I want the grid overlay.
img {
filter: url(#duotone_filter)
}
.img-container {
display: inline-block;
overflow: hidden;
position: relative;
height: 375px;
}
.img-container::after {
content: '';
display: block;
position: absolute;
background-image: url('http://www.freeiconspng.com/uploads/grid-png-31.png');
background-size: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
<div class="img-container"><img src="http://kb4images.com/images/random-image/37670495-random-image.jpg" /></div>
<svg xmlns="http://www.w3.org/2000/svg">
<filter id="duotone_filter">
<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">
<feFuncR type="table" tableValues="0.0039525691 0.5764705882"></feFuncR>
<feFuncG type="table" tableValues="0.0123456790 0.8431372549"></feFuncG>
<feFuncB type="table" tableValues="0.0123456790 0.9803921569"></feFuncB>
<feFuncA type="table" tableValues="0 1"></feFuncA>
</feComponentTransfer>
</filter>
</svg>
Also an example using only SVGs (symbols):
One final example that also works in Firefox and uses two SVG filters. The key to this example is that it uses another filter to create a composite image. I took another SVG from the web but you could use an inline SVG and reference it by ID as well.
<filter id="overlay">
<feImage result="sourceTwo" xlink:href="http://www.vectorstash.com/vectors/vectorstash-grid.svg" width="500" height="375" preserveAspectRatio="none" x="0" y="0" />
<feComposite in="SourceGraphic" in2="sourceTwo" operator="out" x="0" y="0" />
</filter>
A handy way to do this is to combine the grid overlay with the filter by putting inline SVG for the grid into an feImage primitive.
(I also changed your greyscale matrix because it was only using the red channel as source which is going to create weird results on blue/green heavy photos.)
.filterclass {
filter: url(#duotone_filter);
}
<svg xmlns="http://www.w3.org/2000/svg">
<filter id="duotone_filter" color-interpolation-filters="sRGB" x="0%" y="0%" width="100%" height="100%">
<feImage width="6" height="6" xlink:href= "data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20x%3D%220%22%20y%3D%220%22%20width%3D%226px%22%20height%3D%226px%22%20viewBox%3D%220%200%206%206%22%3E%0A%20%20%20%3Crect%20x%3D%220%22%20y%3D%220%22%20width%3D%226%22%20height%3D%226%22%20fill%3D%22none%22%20stroke%3D%22grey%22/%3E%0A%3C/svg%3E"/>
<feTile result="overlay"/>
<feColorMatrix in="SourceGraphic" type="matrix" result="grayscale"
values=".33 .33 .33 0 0
.33 .33 .33 0 0
.33 .33 .33 0 0
0 0 0 1 0" />
<feComponentTransfer result="duotone">
<feFuncR type="table" tableValues="0.0039525691 0.5764705882"></feFuncR>
<feFuncG type="table" tableValues="0.0123456790 0.8431372549"></feFuncG>
<feFuncB type="table" tableValues="0.0123456790 0.9803921569"></feFuncB>
<feFuncA type="table" tableValues="0 1"></feFuncA>
</feComponentTransfer>
<feBlend mode="multiply" in="overlay"/>
</filter>
</svg>
<div >
<img class="filterclass" src="http://kb4images.com/images/random-image/37670495-random-image.jpg" />
</div>
The source SVG for the inlined data uri is
<svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="6px" height="6px" viewBox="0 0 6 6">
<rect x="0" y="0" width="6" height="6" fill="none" stroke="grey"/>
</svg>
If you want to tweak it - I use this converter for svg+xml - which is pretty useful https://codepen.io/yoksel/details/JDqvs
I have a very fancy font I want to use in SVG so I can combine it with other things in an SVG for a final product. It clips off the overhangs and other fancy bits beyond the base font size. How do I get those to show again? For some reason, the snippet is not reading my font URL but my own file reads and displays it fine, so do whatever you need to do to get it to work enough for testing purposes.
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/css" href="http://www.cafenocturne.com/fonts/FontPorcelain.css" ?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewbox="0 0 500 300">
<defs>
<filter id="dropshadow" width="250px" height="250px">
<feOffset result="offOut" in="SourceAlpha" dx="3" dy="3" />
<feGaussianBlur result="blurOut" in="offOut" stdDeviation="3" />
<feBlend in="SourceGraphic" in2="blurOut" mode="normal" />
</filter>
</defs>
<text x="80" y="80" style="font-family: PorcelainRegular;
font-size: 80px;
stroke: #000000;
fill: #ffffff;
filter: url(#dropshadow);">
Cafe
</text>
<text x="80" y="150" style="font-family: PorcelainRegular;
font-size : 80px;
stroke : #000000;
fill : #ffffff;
filter: url(#dropshadow);">
Nocturne
</text>
</svg>