-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Masking an animated GIF loaded with loadImage() not working. #5174
Comments
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already. |
Hi @sandersturing thanks for the well-written issue. This is an example of something that was simply forgotten. Often when new features are added (gifs in this case) it is easy to forget all of the different ways people will expect to be able to use them. If someone wants to take this on they will need to update the mask function so that it:
|
Hello @stalgiag, thanks for the reaction! Is this something I can implement myself locally for now? |
This works okay in a pinch. function preload() {
gif = loadImage('gif.gif');
mask = loadImage('mask.png');
}
function setup() {
createCanvas(800, 800);
background(200, 100, 100);
pixelDensity(1);
const pg = createGraphics(gif.width, gif.height);
const ctx = pg.drawingContext;
for (let i = 0; i < gif.gifProperties.frames.length; i++) {
ctx.drawImage(mask.canvas, 0, 0);
ctx.globalCompositeOperation = 'source-in';
gif.drawingContext.putImageData(gif.gifProperties.frames[i].image, 0, 0);
ctx.drawImage(gif.canvas, 0, 0);
gif.drawingContext.clearRect(0, 0, gif.width, gif.height);
gif.gifProperties.frames[i].image = ctx.getImageData(0, 0, gif.width, gif.height);
}
} |
@stalgiag Thank you so much, this works well. You're adding the mask to every frame beforehand and save that in the image object itself, right? This will do perfectly for now. Hope it will be implemented in future releases. Thanks again! |
When the mask method is called on an Image that contains an animated GIF, the mask is applied to all of its frames.
resolves processing#5174 When the mask method is called on an Image that contains an animated GIF, the mask is applied to all of its frames.
resolves processing#5174 When the mask method is called on an Image that contains an animated GIF, the mask is applied to all of its frames.
resolves processing#5174 When the mask method is called on an Image that contains an animated GIF, the mask is applied to all of its frames.
resolves processing#5174 When the mask method is called on an Image that contains an animated GIF, the mask is applied to all of its frames.
When loading an animated gif with loadImage() and applying a mask, the image is not masked. Doing the same thing with a still image obviously works:
Example in online editor
Good to add that there seems to be some inconsistency with how different browsers behave (which I could not reproduce myself):
Steps to reproduce:
Expected:
Result:
Thing I tried:
The text was updated successfully, but these errors were encountered: