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;
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
globalCompositeOperation = 'color-dodge'which is equivalent of CSS'
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.