2

I have an SVGimage element and I want that image to have a shadow using feOffset, feGaussianBlur, etc.

and at the same time, I need to set the image's brightness and contrast,

I tried the following code:

<image x="10" y="100" width="440" height="60" xlink:href="/images/pulpit.jpg" preserveAspectRatio="defer" filter="url(#drop)"></image>
<defs>
<filter id="drop" filterUnits="userSpaceOnUse">
  <feComponentTransfer in="SourceAlpha" result="doo">
    <feFuncR type="discrete" tablevalues="3" />

  </feComponentTransfer>
  <feOffset dx="80" dy="0" result="shadow"  in="doo" />
  <feGaussianBlur stdDeviation="20 0" in="shadow" result="blurOut"/>
  <feBlend in="SourceGraphic" in2="blurOut" />

  <feComponentTransfer in="SourceGraphic">
    <feFuncR type="linear" slope="0.4" />
  </feComponentTransfer>
</filter>
<defs>
</svg>

but it ended up only use the last filter (second feComponentTransfer), any ideas to apply for both filter?

the first feComponentTransfer until feBlend is to create a drop shadow, and the second feComponentTransfer is to set the brightness of the image itself(not the shadow)

1
  • Did you try feMerge? It's sole job is to combine filters.
    – john k
    Commented Jan 13, 2015 at 3:07

2 Answers 2

1

Presumably the in of the feComponentTransfer should be blurOut rather than the SourceGraphic which is the original input.

0

It's always best to explicitly add "result" and "in"'s to your filters so you can keep track of what's feeding what. This is what has tripped you up here. As it stands, you have two filter chains that end with blurOut and an unnamed final result. You need to redo the order of your operations to adjust the sourcegraphic separately, then composite it on top of the shadow. Code below. And also...

A few cleanups:

  1. there's no need to set filter units if you're not going to set dimensions on the filter.
  2. feComponentTransfer ceilings values over 1 and floors values below 0, so that 3 - can be a 1.
  3. It is a bug in mozilla that won't give you a proper color conversion when there's only one value in the array - you should repeat the value twice and that will now work in firefox.

Working code is:

<filter id="drop">
  <feComponentTransfer in="SourceAlpha" result="doo">
    <feFuncR type="discrete" tableValues="1 1" />
  </feComponentTransfer>

  <feOffset dx="80" dy="0"  in="doo" result="shadow"/>
  <feGaussianBlur stdDeviation="20 0" in="shadow" result="blurOut"/>

  <feComponentTransfer in="SourceGraphic" result="unbrightsource">
    <feFuncR type="linear" slope="0.4" />
  </feComponentTransfer>

  <feBlend mode="normal" in="unbrightsource" in2="blurOut" result="final"/>


</filter>
3
  • Then it must be a webkit bug that gives you a non-identity transform with one value. I've read that part of the spec a few times and couldn't figure out what's supposed to happen with one value. Commented Feb 23, 2013 at 20:33
  • I just worked through the algorithm from the spec and a single value is valid, so this is indeed a Firefox bug. The spec says - for an input value C, where C<1, and an input array of [V0...Vn-1] find an index k where k/n <= C < (k+1)/n. C' (the output value) is Vk. And where C=1, define k=n-1. In the case where the array has a single value, this reduces to k<=C<k+1. The sole array index we have (0) is a valid solution to this constraint. And where C=1, define k=0. Output values should be whatever the single array value is. Firefox bug - not Webkit. Commented Feb 27, 2013 at 15:56
  • Ok. Filed it as Bug 845985. Commented Feb 27, 2013 at 21:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.