Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

417
Vistas
how to Convert Image to Sketch-like-image using Javascript CANVAS API

Hi so I'm trying to convert an image to sketch-like-image before uploading it to the server, the uploading part is not the problem, the conversion of image to sketch-like-image is. I failed to search a js library that will help me achieve this, and then I found this https://www.freecodecamp.org/news/sketchify-turn-any-image-into-a-pencil-sketch-with-10-lines-of-code-cf67fa4f68ce sample code in python then tried to recreate it using CSS only and I got it correctly using the CSS code below

filter: grayscale(100%) invert(100%) blur(5px);
mix-blend-mode: color-dodge;

Then after that I tried to recreate it in Vanilla Javascript using CANVAS API because I needed the image to be uploaded in the server that looks like a sketch-like-image, but got stuck in the process here are the stages of the conversion I'm doing see image below enter image description here

I got stuck in the stage 4, I can't proceed with the stage 5, which is globalCompositeOperation = 'color-dodge'; when color-dodge applied to CANVAS API, to remove the blur and make it look like an sketch-image

  • stage 1 is the raw image
  • stage 2 is grayscale(100%) working in javascript CANVAS API
  • stage 3 is invert(100%) working in javascript CANVAS API
  • stage 4 is blur(5px) working in javascript CANVAS API
  • stage 5 globalCompositeOperation = 'color-dodge' which is equivalent of CSS' mix-blend-mode: color-dodge; I think? I'm not sure but I assumed it is. not working in javascript CANVAS API

and here's my Javascript code below

  let img = document.createElement('img');
  let canvas = document.createElement('canvas');
  let ctx = canvas.getContext('2d');
  ctx.filter = 'grayscale(100%) invert(100%) blur(5px)'; // stages 2,3,4 is working
  ctx.globalCompositeOperation = 'color-dodge'; // stage 5 not working
  ctx.drawImage(img, 0, 0, canvas.width, canvas.height);

Ok so I think that's a lot so here's a snippet of it for you guys to test it out. https://codepen.io/ohyeahhu/pen/MWQRweP

also if you guys know a JS library or tools that might help me achieve this feat, I'm very open to any suggestions.

note: only in javascript or any js library

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda