context.drawImage
See original GitHub issueHi, any ideas why .addImage wouldn’t work on a context?
PImage.decodeJPEGFromStream(fs.createReadStream(filePath)).then((img) => {
var ctx = img.getContext('2d');
ctx.fillStyle = "red";
ctx.fillRect(0, 0, img.width, img.height);
var maskCanvas = PImage.make(img.width, img.height);
var maskCtx = maskCanvas.getContext('2d');
maskCtx.fillStyle = "black";
maskCtx.fillRect(0, 0, maskCanvas.width, maskCanvas.height);
ctx.drawImage(maskCanvas, 0,0);
PImage.encodeJPEGToStream(img, fs.createWriteStream(saveOut)).then(()=> {
console.log("wrote out the png file to out.png");
}).catch((e)=>{
console.log("there was an error writing");
});
});
Here is a sample where the image should come up black but the drawImage call doesn’t seem to be effective. This should work with any image load, basically just trying to get a working test case before moving on.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
CanvasRenderingContext2D.drawImage() - Web APIs | MDN
The CanvasRenderingContext2D.drawImage() method of the Canvas 2D API provides different ways to draw an image onto the canvas.
Read more >HTML canvas drawImage() Method - W3Schools
The drawImage() method draws an image, canvas, or video onto the canvas. The drawImage() method can also draw parts of an image, and/or...
Read more >How to use the canvas drawImage function | RGraph.net
The canvas drawImage function allows you to add images to your scene. You can also use this function to add videos to your...
Read more >HTML | canvas drawImage() Method - GeeksforGeeks
In HTML5, canvas drawImage() function is used to display an image or video on canvas. This function can be used to display the...
Read more >JavaScript canvas drawImage() method explained
The drawImage() method is a method from the Canvas API that allows you to add an image into your <canvas> element. Just like...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You know, I actually didn’t need xor, I ended up needing destination-atop. I was able to get the implementation working with canvas@next. I imagine I could get it working much better with PureImage — or at least cleaner without binaries flying all over the place. I have very limited experience with imaging/graphics fundamentals though. Mostly just a consumer of the library with that stuff.
Thanks,
Jason J
On January 11, 2018 at 8:40:53 AM, Josh Marinacci (notifications@github.com) wrote:
All of the implementation is from scratch. The many composite ops aren’t implemented yet. However, are you sure you need XOR? That is very rare in modern day graphics systems. What are you trying to accomplish?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/joshmarinacci/node-pureimage/issues/46#issuecomment-356986108, or mute the thread https://github.com/notifications/unsubscribe-auth/AEorqHrQO99sGjiTwlM5y7hFesFHvimzks5tJjmVgaJpZM4RXXNB .
No, it turned out that I needed to wait half a second before encoding the image. Yes, otl -> outline.png. That solved the problem but then revealed another issue 😉. I was able to get around it, but I opened an issue for the functionality.