mask — Apply an alpha mask to an image

Description

public Intervention\Image\Image mask(mixed $source, [bool $mask_with_alpha])

Apply a given image source as alpha mask to the current image. By default the image’s red channel is converted to alpha values, but you can set mask_with_alpha to apply the actual alpha channel. The transparency values of the current image will be maintained.

Parameters

source

The image source that will be applied as alpha mask. The method can handle the following types of input:

  • string - Path of the image in filesystem.
  • string - Binary image data.
  • resource - PHP resource of type gd.
  • object - Instance of Intervention\Image\Image

mask_with_alpha (optional)

Set this to true to apply the actual alpha channel as mask to the current image instead of the color values. Default: false

Return Values

Instance of Intervention\Image\Image

Examples

  1. // create new Intervention Image
  2. $img = Image::make('public/foo.jpg');
  3. // Apply another image as alpha mask on image
  4. $img->mask('public/mask.png');
  5. // Apply a second image with alpha channel masking
  6. $img->mask('public/alpha.png', true);

See also