Using the mask() method, you can create a mask for an image to specify the transparency in different parts of the image. To run this example locally, you will need two image files and a running local server.
Alpha Mask by p5.js Contributors and the Processing Foundation is licensed under CC BY-NC-SA 4.0.
Related Examples
![Three columns of the words “ichi,” “ni,” “san,” and “shi” on a white background. The first column is right aligned, the middle column is center aligned, and the left column is left aligned.](/_astro/03_Imported_Media-00_Words-thumbnail.B0ocGCfk_Z18RDyX.webp)
Three columns of the words “ichi,” “ni,” “san,” and “shi” on a white background. The first column is right aligned, the middle column is center aligned, and the left column is left aligned.
Words
Load fonts and draw text.
![Black-and-white photograph of a parrot. A curvy line is drawn across the image; within the confines of that line, color is added to the photograph.](/_astro/03_Imported_Media-01_Copy_Image_Data-thumbnail.C_M5-Apf_Z1ShDY6.webp)
Black-and-white photograph of a parrot. A curvy line is drawn across the image; within the confines of that line, color is added to the photograph.
Copy Image Data
Paint from an image file onto the canvas.
![Two leaf sprigs side by side on a white background. The right sprig is labeled "Mask." The left sprig is labeled "Masked Image," and uses the shape of the right sprig to mask a photograph of tulips.](/_astro/03_Imported_Media-02_Alpha_Mask-thumbnail.Cu0OO42U_1jXtbX.webp)
Two leaf sprigs side by side on a white background. The right sprig is labeled "Mask." The left sprig is labeled "Masked Image," and uses the shape of the right sprig to mask a photograph of tulips.
Alpha Mask
Use one image to cut out a section of another image.
![An astronaut on a planet as the background with a slightly transparent version of this image overlaid and to the left.](/_astro/03_Imported_Media-03_Image_Transparency-thumbnail.Cds7LBFq_Z2i3fPS.webp)
An astronaut on a planet as the background with a slightly transparent version of this image overlaid and to the left.
Image Transparency
Make an image translucent on the canvas.
![A close up of an audio player timestamp, reading "0:00 / 2."](/_astro/03_Imported_Media-04_Create_Audio-thumbnail.freIsbi7_2nfLeB.webp)
A close up of an audio player timestamp, reading "0:00 / 2."
Audio Player
Create a player for an audio file.
![A screenshot of a video of a hand, with the pointer finger touching a desk.](/_astro/03_Imported_Media-05_Video-thumbnail.2aa8-8AD_ZwCeux.webp)
A screenshot of a video of a hand, with the pointer finger touching a desk.
Video Player
Create a player for a video file.
![Two overlaid screenshots of a video of a hand, with the pointer finger touching a desk. Text to the top right of the screenshot reads "Click the canvas to start and pause the video feed."](/_astro/03_Imported_Media-06_Video_Canvas-thumbnail.BlkAL3PB_ZMnFsG.webp)
Two overlaid screenshots of a video of a hand, with the pointer finger touching a desk. Text to the top right of the screenshot reads "Click the canvas to start and pause the video feed."
Video on Canvas
Display and stylize a video on the canvas.
![An inverse, black and white photograph of trees.](/_astro/03_Imported_Media-07_Video_Capture-thumbnail.BoO0NmjW_Z2mN7ra.webp)
An inverse, black and white photograph of trees.
Video Capture
Display a live video feed from a camera.