block by mbostock 1342359

SVG feGaussianBlur

Full Screen

A demonstration of SVG’s Gaussian blur filter effect: the svg:feGaussianBlur element.

Image source: GitHub’s octodex.

index.html

<!DOCTYPE html>
<meta charset="utf-8">
<style>

body {
  position: relative;
  width: 960px;
  height: 500px;
}

input {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 200px;
}

</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>

var svg = d3.select("body").append("svg")
    .attr("width", 960)
    .attr("height", 500);

var filter = svg.append("defs")
  .append("filter")
    .attr("id", "blur")
  .append("feGaussianBlur")
    .attr("stdDeviation", 5);

d3.select("body").append("input")
    .attr("type", "range")
    .attr("min", 0)
    .attr("max", 100)
    .attr("value", 25)
    .on("change", blur);

var image = new Image;
image.src = "octocat.jpg";
image.onload = load;

function load() {
  svg.append("image")
      .attr("xlink:href", this.src)
      .attr("width", "100%")
      .attr("height", "100%")
      .attr("filter", "url(#blur)");
}

function blur() {
  filter.attr("stdDeviation", this.value / 5);
}

</script>