Skip to main content

HTML5 Canvas Sepia filter Image Tutorial

To apply filter to an Konva.Image, we have to cache it first with cache() function. Then apply filter with filters() function.

To apply a sepia effect to an image with Konva, we can use the Konva.Filters.Sepia.

For all available filters go to Filters Documentation.

import Konva from 'konva';

const stage = new Konva.Stage({
  container: 'container',
  width: window.innerWidth,
  height: window.innerHeight,
});

const layer = new Konva.Layer();
stage.add(layer);

const imageObj = new Image();
imageObj.onload = () => {
  const image = new Konva.Image({
    x: 50,
    y: 50,
    image: imageObj,
    draggable: true,
  });

  layer.add(image);

  // Apply Sepia filter
  image.cache();
  image.filters([Konva.Filters.Sepia]);
  layer.draw();
};
imageObj.src = '/images/lion.png';