can i remove a background from an image using Js

hey guy i was wondering if i can create a javascript api that removes the background from an Image , does js have that capability ?
18 Replies
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
johnny  the fifth
johnny the fifthOP•3y ago
does js has that capability anyways ?
Daryl
Daryl•3y ago
Manipulating video using canvas - Web APIs | MDN
By combining the capabilities of the video element with a canvas, you can manipulate video data in real time to incorporate a variety of visual effects to the video being displayed. This tutorial demonstrates how to perform chroma-keying (also known as the "green screen effect") using JavaScript code.
mey
mey•3y ago
basically you will want to load the image, loop through the image data replacing remove colors matching your "background" color with transparency while copying everything to a new array of image data, then redraw that imagedata to a new canvas and export it
johnny  the fifth
johnny the fifthOP•3y ago
any solution involving canvas didn't work 😔
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
mey
mey•3y ago
what didnt work about canvas? if you ran into a tainted canvas issue there are ways to resolve that
johnny  the fifth
johnny the fifthOP•3y ago
the output was a disaster plus is canvas the only way to do it ?
mey
mey•3y ago
Canvas is the only way I know if you want pure browser JS. But if you want to host a server you can do that.
johnny  the fifth
johnny the fifthOP•3y ago
what's the best way to find another solution ?
mey
mey•3y ago
I hate to be that person but we've given you all the ways we know to do this. If the output was pure disaster you may have been doing it wrong
johnny  the fifth
johnny the fifthOP•3y ago
well maybe ur right it's fine don't hate yourself sry if i made u feel that way it
shaaah
shaaah•3y ago
Canvas is the way to go about it like @Lizzy A mentioned Now if you can't achieve it then use a paid service https://clipdrop.co/apis/docs/remove-background#:~:text=Remove%20Background%20API%E2%80%8B,the%20original%20image%20to%20process.
Remove Background | ClipDrop APIs
Quickly remove the background of any image with incredible accuracy
johnny  the fifth
johnny the fifthOP•3y ago
it works with very small images if it gets to certain size it looks so bad i have already tried that i am refering to canvas here
mey
mey•3y ago
I recommend googling "what is a threshold" Specifically search for mathematical results As the only way I can see the output looking disgusting is if you only removed a pure color like #ffffff Photos blend all the time so this is why you say "anything above 95% this color" for example Photoshop used a similar method for magic selects back in the day iirc
johnny  the fifth
johnny the fifthOP•3y ago
so u believe that made a mistake somewhere ?
mey
mey•3y ago
i believe that if you aren't already using a threshold value you should be, and if you aren't that's why you're getting garbage results
johnny  the fifth
johnny the fifthOP•3y ago
i never used canvas before that was my first time i found it a bit difficult to understand some of the stuff related to it or i just got bored from trying and getting bad results
Want results from more Discord servers?
Add your server